lamassu-server/lib/coupon-manager.js
Sérgio Salgado 7fe8799edc feat: add loyalty panel screen and structure
feat: add coupons table

feat: add coupons to schema

fix: coupon schema

feat: coupon table

feat: add coupon top button

feat: add first coupon button

feat: delete coupon

feat: coupon modal

fix: clear discount on modal close

fix: modal input formatting

feat: add new coupons

fix: button positioning

fix: remove loyalty panel sidebar

fix: coupon screen matching specs

fix: coupon modal

feat: send coupon data to machine on poll

fix: available coupons bool

feat: coupon endpoint

feat: transaction discount migration

feat: post-discount rates

refactor: bills

feat: version string

fix: bill saving on db

feat: coupon soft-delete

fix: coupon soft delete

fix: bill receiving

feat: remove cryptoAtoms update during tx

fix: tx trading

fix: bills

feat: start trades rework

fix: remove code

fix: code review
2021-01-18 19:42:03 +00:00

24 lines
727 B
JavaScript

const db = require('./db')
const uuid = require('uuid')
function getAvailableCoupons () {
const sql = `select * from coupons where soft_deleted=false`
return db.any(sql)
}
function getCoupon (code) {
const sql = `select * from coupons where code=$1 and soft_deleted=false`
return db.oneOrNone(sql, [code])
}
function createCoupon (code, discount) {
const sql = `insert into coupons (id, code, discount) values ($1, $2, $3) returning *`
return db.one(sql, [uuid.v4(), code, discount])
}
function softDeleteCoupon (couponId) {
const sql = `update coupons set soft_deleted=true where id=$1`
return db.none(sql, [couponId])
}
module.exports = { getAvailableCoupons, getCoupon, createCoupon, softDeleteCoupon }