feat: add discount source column to transaction tables

fix: move individual discounts to phone code response instead of poller
This commit is contained in:
Sérgio Salgado 2021-08-06 18:41:04 +01:00 committed by Josh Harvey
parent e837ee3e7a
commit b0fa62a9f3
6 changed files with 32 additions and 12 deletions

View file

@ -11,6 +11,7 @@ const httpError = require('../route-helpers').httpError
const plugins = require('../plugins')
const Tx = require('../tx')
const respond = require('../respond')
const loyalty = require('../loyalty')
function addOrUpdateCustomer (req) {
const customerData = req.body
@ -37,13 +38,18 @@ function addOrUpdateCustomer (req) {
if (_.isEmpty(patch)) return customer
return customers.update(customer.id, patch)
})
}).then(customer => {
})
.then(customer => {
return Tx.customerHistory(customer.id, maxDaysThreshold)
.then(result => {
customer.txHistory = result
return customer
})
})
.then(customer => {
return loyalty.getCustomerIndividualDiscounts(customer.id)
.then(discount => ({ ...customer, discount }))
})
}
function getCustomerWithPhoneCode (req, res, next) {