feat: put T&C in its own query
This commit is contained in:
parent
7b951f961f
commit
469f38b768
2 changed files with 54 additions and 19 deletions
|
|
@ -68,18 +68,6 @@ const buildTriggers = (allTriggers) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: From `lib/routes/termsAndConditionsRoutes.js` -- remove this after
|
|
||||||
* terms are removed from the GraphQL API too.
|
|
||||||
*/
|
|
||||||
const massageTerms = terms => (terms.active && terms.text) ? ({
|
|
||||||
delay: Boolean(terms.delay),
|
|
||||||
title: terms.title,
|
|
||||||
text: nmd(terms.text),
|
|
||||||
accept: terms.acceptButtonText,
|
|
||||||
cancel: terms.cancelButtonText,
|
|
||||||
}) : null
|
|
||||||
|
|
||||||
const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings, }) => {
|
const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings, }) => {
|
||||||
const massageCoins = _.map(_.pick([
|
const massageCoins = _.map(_.pick([
|
||||||
'batchable',
|
'batchable',
|
||||||
|
|
@ -112,7 +100,6 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
|
||||||
configManager.getLocale(deviceId, settings.config),
|
configManager.getLocale(deviceId, settings.config),
|
||||||
configManager.getOperatorInfo(settings.config),
|
configManager.getOperatorInfo(settings.config),
|
||||||
configManager.getReceipt(settings.config),
|
configManager.getReceipt(settings.config),
|
||||||
massageTerms(configManager.getTermsConditions(settings.config)),
|
|
||||||
!!configManager.getCashOut(deviceId, settings.config).active,
|
!!configManager.getCashOut(deviceId, settings.config).active,
|
||||||
])
|
])
|
||||||
.then(([
|
.then(([
|
||||||
|
|
@ -123,7 +110,6 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
|
||||||
localeInfo,
|
localeInfo,
|
||||||
operatorInfo,
|
operatorInfo,
|
||||||
receiptInfo,
|
receiptInfo,
|
||||||
terms,
|
|
||||||
twoWayMode,
|
twoWayMode,
|
||||||
]) =>
|
]) =>
|
||||||
(currentConfigVersion && currentConfigVersion >= staticConf.configVersion) ?
|
(currentConfigVersion && currentConfigVersion >= staticConf.configVersion) ?
|
||||||
|
|
@ -143,7 +129,6 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
|
||||||
twoWayMode,
|
twoWayMode,
|
||||||
speedtestFiles,
|
speedtestFiles,
|
||||||
urlsToPing,
|
urlsToPing,
|
||||||
terms,
|
|
||||||
}),
|
}),
|
||||||
_.update('triggersAutomation', _.mapValues(_.eq('Automatic'))),
|
_.update('triggersAutomation', _.mapValues(_.eq('Automatic'))),
|
||||||
addOperatorInfo(operatorInfo),
|
addOperatorInfo(operatorInfo),
|
||||||
|
|
@ -232,8 +217,54 @@ const configs = (parent, { currentConfigVersion }, { deviceId, deviceName, opera
|
||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
const massageTerms = terms => (terms.active && terms.text) ? ({
|
||||||
|
delay: Boolean(terms.delay),
|
||||||
|
title: terms.title,
|
||||||
|
text: nmd(terms.text),
|
||||||
|
accept: terms.acceptButtonText,
|
||||||
|
cancel: terms.cancelButtonText,
|
||||||
|
}) : null
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The type of the result of `configManager.getTermsConditions()` is more or
|
||||||
|
* less `Maybe (Maybe Hash, Maybe TC)`. Each case has a specific meaning to the
|
||||||
|
* machine:
|
||||||
|
*
|
||||||
|
* Nothing => Nothing
|
||||||
|
* There are no T&C or they've been removed/disabled.
|
||||||
|
*
|
||||||
|
* Just (Nothing, _) => Nothing
|
||||||
|
* Shouldn't happen! Treated as if there were no T&C.
|
||||||
|
*
|
||||||
|
* Just (Just hash, Nothing) => Nothing
|
||||||
|
* May happen (after `massageTerms`) if T&C are disabled.
|
||||||
|
*
|
||||||
|
* Just (Just hash, Just tc) => Just (hash, Just tc) or Just (hash, Nothing)
|
||||||
|
* `tc` is sent depending on whether the `hash` differs from `currentHash` or
|
||||||
|
* not.
|
||||||
|
*/
|
||||||
|
const terms = (parent, { currentHash }, { settings }, info) => {
|
||||||
|
const isNone = x => _.isNil(x) || _.isEmpty(x)
|
||||||
|
|
||||||
|
const latestTerms = configManager.getTermsConditions(settings.config)
|
||||||
|
if (isNone(latestTerms)) return null
|
||||||
|
|
||||||
|
const hash = latestTerms.hash
|
||||||
|
if (!_.isString(hash)) return null
|
||||||
|
|
||||||
|
if (hash === currentHash) return { hash, details: null }
|
||||||
|
|
||||||
|
const details = massageTerms(latestTerms)
|
||||||
|
if (isNone(details)) return null
|
||||||
|
|
||||||
|
return { hash, details }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Query: {
|
Query: {
|
||||||
configs
|
configs,
|
||||||
|
terms,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ type Trigger {
|
||||||
thresholdDays: Int
|
thresholdDays: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Terms {
|
type TermsDetails {
|
||||||
delay: Boolean!
|
delay: Boolean!
|
||||||
title: String!
|
title: String!
|
||||||
text: String!
|
text: String!
|
||||||
|
|
@ -77,6 +77,11 @@ type Terms {
|
||||||
cancel: String!
|
cancel: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Terms {
|
||||||
|
hash: String!
|
||||||
|
details: TermsDetails
|
||||||
|
}
|
||||||
|
|
||||||
type StaticConfig {
|
type StaticConfig {
|
||||||
configVersion: Int!
|
configVersion: Int!
|
||||||
|
|
||||||
|
|
@ -98,8 +103,6 @@ type StaticConfig {
|
||||||
|
|
||||||
triggersAutomation: TriggersAutomation!
|
triggersAutomation: TriggersAutomation!
|
||||||
triggers: [Trigger!]!
|
triggers: [Trigger!]!
|
||||||
|
|
||||||
terms: Terms
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DynamicCoinValues {
|
type DynamicCoinValues {
|
||||||
|
|
@ -147,5 +150,6 @@ type Configs {
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
configs(currentConfigVersion: Int): Configs!
|
configs(currentConfigVersion: Int): Configs!
|
||||||
|
terms(currentHash: String): Terms
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue