diff --git a/lib/graphql/resolvers.js b/lib/graphql/resolvers.js index 62c24d4b..e831f4d3 100644 --- a/lib/graphql/resolvers.js +++ b/lib/graphql/resolvers.js @@ -1,4 +1,5 @@ const _ = require('lodash/fp') +const nmd = require('nano-markdown') const { accounts: accountsConfig, countries, languages } = require('../new-admin/config') const plugins = require('../plugins') @@ -65,6 +66,18 @@ 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 = (parent, { currentConfigVersion }, { deviceId, deviceName, settings }, info) => Promise.all([ plugins(settings, deviceId).staticConfigQueries(), @@ -75,6 +88,7 @@ const staticConfig = (parent, { currentConfigVersion }, { deviceId, deviceName, configManager.getLocale(deviceId, settings.config), configManager.getOperatorInfo(settings.config), configManager.getReceipt(settings.config), + massageTerms(configManager.getTermsConditions(settings.config)), !!configManager.getCashOut(deviceId, settings.config).active, ]) .then(([ @@ -86,6 +100,7 @@ const staticConfig = (parent, { currentConfigVersion }, { deviceId, deviceName, localeInfo, operatorInfo, receiptInfo, + terms, twoWayMode, ]) => (currentConfigVersion && currentConfigVersion >= staticConf.configVersion) ? @@ -105,6 +120,7 @@ const staticConfig = (parent, { currentConfigVersion }, { deviceId, deviceName, twoWayMode, speedtestFiles, urlsToPing, + terms, }), _.update('triggersAutomation', _.mapValues(_.eq('Automatic'))), addOperatorInfo(operatorInfo), diff --git a/lib/graphql/types.js b/lib/graphql/types.js index 1c8161ea..7e504182 100644 --- a/lib/graphql/types.js +++ b/lib/graphql/types.js @@ -69,6 +69,14 @@ type Trigger { thresholdDays: Int } +type Terms { + delay: Boolean! + title: String! + text: String! + accept: String! + cancel: String! +} + type StaticConfig { configVersion: Int! @@ -90,6 +98,8 @@ type StaticConfig { triggersAutomation: TriggersAutomation! triggers: [Trigger!]! + + terms: Terms } type DynamicCoinValues {