API Data Fetcher replaceBy Config Property Extended

This commit is contained in:
Luis Fernando Molina committed 2021-05-31 18:16:52 +02:00
1 parent 366336097e
commit e2dc178ec1
4 files changed
+133 -15

No files matched your search

@@ -346,9 +346,19 @@ exports.newSuperalgosBotModulesFetchingProcess = function (processIndex) {
if (apiQueryParameter.config.isPageNumber === true) {
pageNumberParameter = apiQueryParameter
} else {
/*
Whatever is in Value is the default value.
*/
if (apiQueryParameter.config.codeName !== undefined && apiQueryParameter.config.value !== undefined) {
parametersMap.set(apiQueryParameter.config.codeName, apiQueryParameter.config.value)
}
/*
If there is a replace action to be made, then that could replace the default value.
*/
let replaceValue = checkReplaceBy(apiQueryParameter)
if (replaceValue !== undefined) {
parametersMap.set(apiQueryParameter.config.codeName, replaceValue)
}
}
}
}
@@ -393,23 +403,42 @@ exports.newSuperalgosBotModulesFetchingProcess = function (processIndex) {
if (pathString === "") { pathString = '/' }
let apiPathParameter = value
let parameterValue = key // This is the default value
if (apiPathParameter.config.replaceBy !== undefined) {
switch (apiPathParameter.config.replaceBy) {
case '@BaseAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName
break
}
case '@QuotedAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
break
}
}
let replaceValue = checkReplaceBy(apiPathParameter)
if (replaceValue !== undefined) {
parameterValue = replaceValue
}
pathString = pathString + separator + parameterValue
separator = "/"
}
}
function checkReplaceBy(apiParameter) {
let parameterValue
if (apiParameter.config.replaceBy !== undefined) {
switch (apiParameter.config.replaceBy) {
case '@BaseAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.baseAsset.referenceParent.config.codeName
break
}
case '@QuotedAsset': {
parameterValue = TS.projects.superalgos.globals.taskConstants.TASK_NODE.parentNode.parentNode.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
break
}
case '@BeginCurrentMinute': {
parameterValue = Math.trunc((new Date()).valueOf() / TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS) * TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS
break
}
case '@EndCurrentMinute': {
parameterValue = Math.trunc((new Date()).valueOf() / TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS) * TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS + TS.projects.superalgos.globals.timeConstants.ONE_MIN_IN_MILISECONDS - 1
break
}
}
}
return parameterValue
}
async function fetchAllPages() {
if (pageNumberParameter === undefined) {
@@ -653,7 +682,7 @@ exports.newSuperalgosBotModulesFetchingProcess = function (processIndex) {
resolve('NO_MORE_PAGES')
} else {
resolve('PAGE_FETCHED')
}
}
/*
If we received an errror code, we abort the processing at this point.
*/