From 82314e826f0fce75a1fae8d4d122816db340def9 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <adhisimon@gmail.com> Date: Wed, 23 Feb 2022 16:34:10 +0700 Subject: [PATCH] Add locations on requesting task from CORE --- index.js | 2 ++ lib/compose-gateway-locations.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 lib/compose-gateway-locations.js diff --git a/index.js b/index.js index 272ad78..489097c 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ const logger = require('tektrans-logger'); const report = require('./lib/report'); const sleep = require('./lib/sleep'); +const composeGatewayLocations = require('./lib/compose-gateway-locations'); let partner; let first = true; @@ -56,6 +57,7 @@ async function getTask() { const payload = { handler: config.handler || config.handler_name, products: config.products || [], + locations: composeGatewayLocations(config), }; let task; diff --git a/lib/compose-gateway-locations.js b/lib/compose-gateway-locations.js new file mode 100644 index 0000000..83d14a8 --- /dev/null +++ b/lib/compose-gateway-locations.js @@ -0,0 +1,18 @@ +/** + * @param {Object} config + * @param {Array.<string>} [config.locations] + * @returns {Array.<string>} + */ +module.exports = (config) => { + const retval = (( + Array.isArray(config.locations) && config.locations.length && config.locations) + || [] + ) + .filter((item) => typeof item === 'string') + .map((item) => item.trim()) + .filter((item) => item.length); + + if (!retval.length) retval.push('ALL'); + + return retval; +}; -- 1.9.0