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

@ -29,7 +29,7 @@ function getNumberOfAvailablePromoCodes () {
}
function getAvailableIndividualDiscounts () {
const sql = `SELECT * from individual_discounts WHERE soft_deleted=false`
const sql = `SELECT * FROM individual_discounts WHERE soft_deleted=false`
return db.any(sql).then(res => _.map(it => ({
id: it.id,
customerId: it.customer_id,
@ -37,6 +37,20 @@ function getAvailableIndividualDiscounts () {
}), res))
}
function getCustomerIndividualDiscounts (customerId) {
const sql = `SELECT * FROM individual_discounts WHERE customer_id=$1 LIMIT 1`
return db.oneOrNone(sql, [customerId]).then(res => {
if (!_.isNil(res)) {
return {
id: res.id,
customerId: res.customer_id,
discount: res.discount
}
}
return res
})
}
function createIndividualDiscount (customerId, discount) {
const sql = `INSERT INTO individual_discounts (id, customer_id, discount) VALUES ($1, $2, $3)`
return db.none(sql, [uuid.v4(), customerId, discount])
@ -54,6 +68,7 @@ module.exports = {
deletePromoCode,
getNumberOfAvailablePromoCodes,
getAvailableIndividualDiscounts,
getCustomerIndividualDiscounts,
createIndividualDiscount,
deleteIndividualDiscount
}