Merge pull request #1448 from chaotixkilla/fix-undefined-custom-info-graphql-poller
Loosen TriggerAutomation typing to allow for dynamic keying
This commit is contained in:
commit
47b915db64
3 changed files with 26 additions and 6 deletions
|
|
@ -56,6 +56,12 @@ type TriggersAutomation {
|
||||||
idCardData: Boolean!
|
idCardData: Boolean!
|
||||||
facephoto: Boolean!
|
facephoto: Boolean!
|
||||||
usSsn: Boolean!
|
usSsn: Boolean!
|
||||||
|
custom: [CustomTriggersAutomation]
|
||||||
|
}
|
||||||
|
|
||||||
|
type CustomTriggersAutomation {
|
||||||
|
id: ID!
|
||||||
|
type: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomScreen {
|
type CustomScreen {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
const { validate } = require('uuid')
|
||||||
|
|
||||||
const namespaces = {
|
const namespaces = {
|
||||||
ADVANCED: 'advanced',
|
ADVANCED: 'advanced',
|
||||||
|
|
@ -117,10 +118,12 @@ const getGlobalNotifications = config => getNotifications(null, null, config)
|
||||||
const getTriggers = _.get('triggers')
|
const getTriggers = _.get('triggers')
|
||||||
|
|
||||||
/* `customInfoRequests` is the result of a call to `getCustomInfoRequests` */
|
/* `customInfoRequests` is the result of a call to `getCustomInfoRequests` */
|
||||||
const getTriggersAutomation = (customInfoRequests, config) => {
|
const getTriggersAutomation = (customInfoRequests, config, oldFormat = false) => {
|
||||||
return customInfoRequests
|
return customInfoRequests
|
||||||
.then(infoRequests => {
|
.then(infoRequests => {
|
||||||
const defaultAutomation = _.get('triggersConfig_automation')(config)
|
const defaultAutomation = _.get('triggersConfig_automation')(config)
|
||||||
|
const overrides = _.get('triggersConfig_overrides')(config)
|
||||||
|
|
||||||
const requirements = {
|
const requirements = {
|
||||||
sanctions: defaultAutomation,
|
sanctions: defaultAutomation,
|
||||||
idCardPhoto: defaultAutomation,
|
idCardPhoto: defaultAutomation,
|
||||||
|
|
@ -129,14 +132,25 @@ const getTriggersAutomation = (customInfoRequests, config) => {
|
||||||
usSsn: defaultAutomation
|
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 => {
|
_.forEach(it => {
|
||||||
requirements[it.id] = defaultAutomation
|
requirements.custom.push({ id: it.id, type: defaultAutomation })
|
||||||
}, infoRequests)
|
}, infoRequests)
|
||||||
|
|
||||||
const overrides = _.get('triggersConfig_overrides')(config)
|
|
||||||
|
|
||||||
const requirementsOverrides = _.reduce((acc, override) => {
|
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)
|
}, {}, overrides)
|
||||||
|
|
||||||
return _.assign(requirements, requirementsOverrides)
|
return _.assign(requirements, requirementsOverrides)
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ function poll (req, res, next) {
|
||||||
pi.recordPing(deviceTime, machineVersion, machineModel),
|
pi.recordPing(deviceTime, machineVersion, machineModel),
|
||||||
pi.pollQueries(),
|
pi.pollQueries(),
|
||||||
buildTriggers(configManager.getTriggers(settings.config)),
|
buildTriggers(configManager.getTriggers(settings.config)),
|
||||||
configManager.getTriggersAutomation(getCustomInfoRequests(true), settings.config),
|
configManager.getTriggersAutomation(getCustomInfoRequests(true), settings.config, true),
|
||||||
])
|
])
|
||||||
.then(([_pingRes, results, triggers, triggersAutomation]) => {
|
.then(([_pingRes, results, triggers, triggersAutomation]) => {
|
||||||
const reboot = pid && state.reboots?.[operatorId]?.[deviceId] === pid
|
const reboot = pid && state.reboots?.[operatorId]?.[deviceId] === pid
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue