refactor: separate T&C text from rest of detials
This commit is contained in:
parent
0213ceb7fe
commit
c5e7627afb
2 changed files with 14 additions and 8 deletions
|
|
@ -244,21 +244,27 @@ const massageTerms = terms => (terms.active && terms.text) ? ({
|
||||||
* `tc` is sent depending on whether the `hash` differs from `currentHash` or
|
* `tc` is sent depending on whether the `hash` differs from `currentHash` or
|
||||||
* not.
|
* not.
|
||||||
*/
|
*/
|
||||||
const terms = (parent, { currentHash }, { settings }, info) => {
|
const terms = (parent, { currentConfigVersion, currentHash }, { deviceId, settings }, info) => {
|
||||||
const isNone = x => _.isNil(x) || _.isEmpty(x)
|
const isNone = x => _.isNil(x) || _.isEmpty(x)
|
||||||
|
|
||||||
const latestTerms = configManager.getTermsConditions(settings.config)
|
let latestTerms = configManager.getTermsConditions(settings.config)
|
||||||
if (isNone(latestTerms)) return null
|
if (isNone(latestTerms)) return null
|
||||||
|
|
||||||
const hash = latestTerms.hash
|
const hash = latestTerms.hash
|
||||||
if (!_.isString(hash)) return null
|
if (!_.isString(hash)) return null
|
||||||
|
|
||||||
if (hash === currentHash) return { hash, details: null }
|
latestTerms = massageTerms(latestTerms)
|
||||||
|
if (isNone(latestTerms)) return null
|
||||||
|
|
||||||
const details = massageTerms(latestTerms)
|
const isHashNew = hash !== currentHash
|
||||||
if (isNone(details)) return null
|
const text = isHashNew ? latestTerms.text : null
|
||||||
|
|
||||||
return { hash, details }
|
return plugins(settings, deviceId)
|
||||||
|
.fetchCurrentConfigVersion()
|
||||||
|
.catch(() => null)
|
||||||
|
.then(configVersion => isHashNew || _.isNil(currentConfigVersion) || currentConfigVersion < configVersion)
|
||||||
|
.then(isVersionNew => isVersionNew ? _.omit(['text'], latestTerms) : null)
|
||||||
|
.then(details => ({ hash, details, text }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,13 +72,13 @@ type Trigger {
|
||||||
type TermsDetails {
|
type TermsDetails {
|
||||||
delay: Boolean!
|
delay: Boolean!
|
||||||
title: String!
|
title: String!
|
||||||
text: String!
|
|
||||||
accept: String!
|
accept: String!
|
||||||
cancel: String!
|
cancel: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type Terms {
|
type Terms {
|
||||||
hash: String!
|
hash: String!
|
||||||
|
text: String
|
||||||
details: TermsDetails
|
details: TermsDetails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,6 +150,6 @@ type Configs {
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
configs(currentConfigVersion: Int): Configs!
|
configs(currentConfigVersion: Int): Configs!
|
||||||
terms(currentHash: String): Terms
|
terms(currentHash: String, currentConfigVersion: Int): Terms
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue