fix: make paper & SMS receipts independent

This commit is contained in:
André Sá 2022-07-04 18:05:31 +01:00 committed by André Sá
parent 206b8cfa09
commit 2ec09de962
2 changed files with 21 additions and 6 deletions

View file

@ -23,16 +23,18 @@ const speedtestFiles = [
]
const addSmthInfo = (dstField, srcFields) => smth =>
smth && smth.active ? _.set(dstField, _.pick(srcFields, smth)) : _.identity
(smth && smth.active) ? _.set(dstField, _.pick(srcFields, smth)) : _.identity
const addOperatorInfo = addSmthInfo(
'operatorInfo',
['name', 'phone', 'email', 'website', 'companyNumber']
)
const addReceiptInfo = addSmthInfo(
'receiptInfo',
[
const addReceiptInfo = receiptInfo => ret => {
if (!receiptInfo) return ret
const fields = [
'paper',
'sms',
'operatorWebsite',
'operatorEmail',
@ -43,10 +45,22 @@ const addReceiptInfo = addSmthInfo(
'exchangeRate',
'addressQRCode',
]
)
const defaults = _.fromPairs(_.map(field => [field, false], fields))
receiptInfo = _.flow(
o => _.set('paper', o.active, o),
_.assign(defaults),
_.pick(fields),
)(receiptInfo)
return (receiptInfo.paper || receiptInfo.sms) ?
_.set('receiptInfo', receiptInfo, ret) :
ret
}
/* TODO: Simplify this. */
const buildTriggers = (allTriggers) => {
const buildTriggers = allTriggers => {
const normalTriggers = []
const customTriggers = _.filter(o => {
if (_.isEmpty(o.customInfoRequestId) || _.isNil(o.customInfoRequestId)) normalTriggers.push(o)