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
This commit is contained in:
Sérgio Salgado 2020-10-28 11:15:20 +00:00 committed by Josh Harvey
parent 64315cfd80
commit 7fe8799edc
18 changed files with 622 additions and 13 deletions

View file

@ -25,6 +25,8 @@ const E = require('./error')
const customers = require('./customers')
const logs = require('./logs')
const compliance = require('./compliance')
const couponManager = require('./coupon-manager')
const BN = require('./bn')
const version = require('../package.json').version
@ -213,6 +215,37 @@ function verifyTx (req, res, next) {
.catch(next)
}
function verifyCoupon (req, res, next) {
couponManager.getCoupon(req.body.codeInput)
.then(coupon => {
if (!coupon) return next()
const transaction = req.body.tx
const commissions = configManager.getCommissions(transaction.cryptoCode, req.deviceId, req.settings.config)
const tickerRate = BN(transaction.rawTickerPrice)
const discount = getDiscountRate(coupon.discount, commissions[transaction.direction])
const rates = {
[transaction.cryptoCode]: {
[transaction.direction]: (transaction.direction === 'cashIn')
? tickerRate.mul(discount).round(5)
: tickerRate.div(discount).round(5)
}
}
respond(req, res, {
coupon: coupon,
newRates: rates
})
})
.catch(next)
}
function getDiscountRate (discount, commission) {
const percentageDiscount = BN(1).sub(BN(discount).div(100))
const percentageCommission = BN(commission).div(100)
return BN(1).add(percentageDiscount.mul(percentageCommission))
}
function addOrUpdateCustomer (req) {
const customerData = req.body
const machineVersion = req.query.version
@ -450,7 +483,8 @@ const configRequiredRoutes = [
'/event',
'/phone_code',
'/customer',
'/tx'
'/tx',
'/verify_coupon'
]
const app = express()
@ -477,6 +511,7 @@ app.post('/state', stateChange)
app.post('/verify_user', verifyUser)
app.post('/verify_transaction', verifyTx)
app.post('/verify_coupon', verifyCoupon)
app.post('/phone_code', getCustomerWithPhoneCode)
app.patch('/customer/:id', updateCustomer)