diff --git a/lib/graphql/types.js b/lib/graphql/types.js index e3278d64..49fb64bb 100644 --- a/lib/graphql/types.js +++ b/lib/graphql/types.js @@ -56,6 +56,12 @@ type TriggersAutomation { idCardData: Boolean! facephoto: Boolean! usSsn: Boolean! + custom: [CustomTriggersAutomation] +} + +type CustomTriggersAutomation { + id: ID! + type: String! } type CustomScreen { diff --git a/lib/new-config-manager.js b/lib/new-config-manager.js index 58c282fc..17a63adc 100644 --- a/lib/new-config-manager.js +++ b/lib/new-config-manager.js @@ -1,4 +1,5 @@ const _ = require('lodash/fp') +const { validate } = require('uuid') const namespaces = { ADVANCED: 'advanced', @@ -117,10 +118,12 @@ const getGlobalNotifications = config => getNotifications(null, null, config) const getTriggers = _.get('triggers') /* `customInfoRequests` is the result of a call to `getCustomInfoRequests` */ -const getTriggersAutomation = (customInfoRequests, config) => { +const getTriggersAutomation = (customInfoRequests, config, oldFormat = false) => { return customInfoRequests .then(infoRequests => { const defaultAutomation = _.get('triggersConfig_automation')(config) + const overrides = _.get('triggersConfig_overrides')(config) + const requirements = { sanctions: defaultAutomation, idCardPhoto: defaultAutomation, @@ -129,14 +132,25 @@ const getTriggersAutomation = (customInfoRequests, config) => { usSsn: defaultAutomation } + if (oldFormat) { + _.forEach(it => { requirements[it.id] = defaultAutomation }, infoRequests) + const oldRequirementsOverrides = _.reduce((acc, override) => _.assign(acc, { [override.requirement]: override.automation }), {}, overrides) + return _.assign(requirements, oldRequirementsOverrides) + } + + requirements.custom = [] + _.forEach(it => { - requirements[it.id] = defaultAutomation + requirements.custom.push({ id: it.id, type: defaultAutomation }) }, infoRequests) - const overrides = _.get('triggersConfig_overrides')(config) - const requirementsOverrides = _.reduce((acc, override) => { - return _.assign(acc, { [override.requirement]: override.automation }) + return _.assign( + acc, + !validate(override.requirement) + ? { [override.requirement]: override.automation } + : { custom: [...acc.custom ?? [], { id: override.requirement, type: override.automation }] } + ) }, {}, overrides) return _.assign(requirements, requirementsOverrides) diff --git a/lib/routes/pollingRoutes.js b/lib/routes/pollingRoutes.js index e0f4b4c2..00aacd54 100644 --- a/lib/routes/pollingRoutes.js +++ b/lib/routes/pollingRoutes.js @@ -85,7 +85,7 @@ function poll (req, res, next) { pi.recordPing(deviceTime, machineVersion, machineModel), pi.pollQueries(), buildTriggers(configManager.getTriggers(settings.config)), - configManager.getTriggersAutomation(getCustomInfoRequests(true), settings.config), + configManager.getTriggersAutomation(getCustomInfoRequests(true), settings.config, true), ]) .then(([_pingRes, results, triggers, triggersAutomation]) => { const reboot = pid && state.reboots?.[operatorId]?.[deviceId] === pid