fix: change coupons to promo codes
This commit is contained in:
parent
840afa866d
commit
59cb33570b
8 changed files with 87 additions and 88 deletions
|
|
@ -13,7 +13,7 @@ const settingsLoader = require('../../new-settings-loader')
|
|||
// const tokenManager = require('../../token-manager')
|
||||
const blacklist = require('../../blacklist')
|
||||
const machineEventsByIdBatch = require("../../postgresql_interface").machineEventsByIdBatch
|
||||
const couponManager = require('../../coupons')
|
||||
const promoCodeManager = require('../../promo-codes')
|
||||
|
||||
const serverVersion = require('../../../package.json').version
|
||||
const transactions = require('../transactions')
|
||||
|
|
@ -177,7 +177,7 @@ const typeDefs = gql`
|
|||
ip_address: String
|
||||
}
|
||||
|
||||
type Coupon {
|
||||
type PromoCode {
|
||||
id: ID!
|
||||
code: String!
|
||||
discount: Int!
|
||||
|
|
@ -276,7 +276,7 @@ const typeDefs = gql`
|
|||
config: JSONObject
|
||||
blacklist: [Blacklist]
|
||||
# userTokens: [UserToken]
|
||||
coupons: [Coupon]
|
||||
promoCodes: [PromoCode]
|
||||
cryptoRates: JSONObject
|
||||
fiatRates: [Rate]
|
||||
}
|
||||
|
|
@ -310,8 +310,8 @@ const typeDefs = gql`
|
|||
# revokeToken(token: String!): UserToken
|
||||
deleteBlacklistRow(cryptoCode: String!, address: String!): Blacklist
|
||||
insertBlacklistRow(cryptoCode: String!, address: String!): Blacklist
|
||||
createCoupon(code: String!, discount: Int!): Coupon
|
||||
deleteCoupon(couponId: ID!): Coupon
|
||||
createPromoCode(code: String!, discount: Int!): PromoCode
|
||||
deletePromoCode(codeId: ID!): PromoCode
|
||||
}
|
||||
`
|
||||
|
||||
|
|
@ -362,7 +362,7 @@ const resolvers = {
|
|||
accounts: () => settingsLoader.loadAccounts(),
|
||||
blacklist: () => blacklist.getBlacklist(),
|
||||
// userTokens: () => tokenManager.getTokenList()
|
||||
coupons: () => couponManager.getAvailableCoupons(),
|
||||
promoCodes: () => promoCodeManager.getAvailablePromoCodes(),
|
||||
cryptoRates: () =>
|
||||
settingsLoader.loadLatest().then(settings => {
|
||||
const pi = plugins(settings)
|
||||
|
|
@ -372,7 +372,7 @@ const resolvers = {
|
|||
withoutCommissions: pi.buildRatesNoCommission(r)
|
||||
}
|
||||
})
|
||||
}),
|
||||
}),
|
||||
fiatRates: () => forex.getFiatRates()
|
||||
},
|
||||
Mutation: {
|
||||
|
|
@ -396,8 +396,8 @@ const resolvers = {
|
|||
insertBlacklistRow: (...[, { cryptoCode, address }]) =>
|
||||
blacklist.insertIntoBlacklist(cryptoCode, address),
|
||||
// revokeToken: (...[, { token }]) => tokenManager.revokeToken(token)
|
||||
createCoupon: (...[, { code, discount }]) => couponManager.createCoupon(code, discount),
|
||||
deleteCoupon: (...[, { couponId }]) => couponManager.deleteCoupon(couponId)
|
||||
createPromoCode: (...[, { code, discount }]) => promoCodeManager.createPromoCode(code, discount),
|
||||
deletePromoCode: (...[, { codeId }]) => promoCodeManager.deletePromoCode(codeId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const machineLoader = require('./machine-loader')
|
|||
const customers = require('./customers')
|
||||
const coinUtils = require('./coin-utils')
|
||||
const commissionMath = require('./commission-math')
|
||||
const coupons = require('./coupons')
|
||||
const promoCodes = require('./promo-codes')
|
||||
|
||||
const mapValuesWithKey = _.mapValues.convert({
|
||||
cap: false
|
||||
|
|
@ -224,13 +224,13 @@ function plugins (settings, deviceId) {
|
|||
const testnetPromises = cryptoCodes.map(c => wallet.cryptoNetwork(settings, c))
|
||||
const pingPromise = recordPing(deviceTime, machineVersion, machineModel)
|
||||
const currentConfigVersionPromise = fetchCurrentConfigVersion()
|
||||
const currentAvailableCoupons = coupons.getNumberOfAvailableCoupons()
|
||||
const currentAvailablePromoCodes = promoCodes.getNumberOfAvailablePromoCodes()
|
||||
|
||||
const promises = [
|
||||
buildAvailableCassettes(),
|
||||
pingPromise,
|
||||
currentConfigVersionPromise
|
||||
].concat(tickerPromises, balancePromises, testnetPromises, currentAvailableCoupons)
|
||||
].concat(tickerPromises, balancePromises, testnetPromises, currentAvailablePromoCodes)
|
||||
|
||||
return Promise.all(promises)
|
||||
.then(arr => {
|
||||
|
|
@ -242,7 +242,7 @@ function plugins (settings, deviceId) {
|
|||
const testNets = arr.slice(2 * cryptoCodesCount + 3, arr.length - 1)
|
||||
const coinParams = _.zip(cryptoCodes, testNets)
|
||||
const coinsWithoutRate = _.map(mapCoinSettings, coinParams)
|
||||
const areThereAvailableCoupons = arr[arr.length - 1] > 0
|
||||
const areThereAvailablePromoCodes = arr[arr.length - 1] > 0
|
||||
|
||||
return {
|
||||
cassettes,
|
||||
|
|
@ -250,7 +250,7 @@ function plugins (settings, deviceId) {
|
|||
balances: buildBalances(balances),
|
||||
coins: _.zipWith(_.assign, coinsWithoutRate, tickers),
|
||||
configVersion,
|
||||
areThereAvailableCoupons
|
||||
areThereAvailablePromoCodes
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
const db = require('./db')
|
||||
const uuid = require('uuid')
|
||||
|
||||
function getAvailableCoupons () {
|
||||
function getAvailablePromoCodes () {
|
||||
const sql = `SELECT * FROM coupons WHERE soft_deleted=false`
|
||||
return db.any(sql)
|
||||
}
|
||||
|
||||
function getCoupon (code) {
|
||||
function getPromoCode (code) {
|
||||
const sql = `SELECT * FROM coupons WHERE code=$1 AND soft_deleted=false`
|
||||
return db.oneOrNone(sql, [code])
|
||||
}
|
||||
|
||||
function createCoupon (code, discount) {
|
||||
function createPromoCode (code, discount) {
|
||||
const sql = `INSERT INTO coupons (id, code, discount) VALUES ($1, $2, $3) RETURNING *`
|
||||
return db.one(sql, [uuid.v4(), code, discount])
|
||||
}
|
||||
|
||||
function deleteCoupon (couponId) {
|
||||
function deletePromoCode (id) {
|
||||
const sql = `UPDATE coupons SET soft_deleted=true WHERE id=$1`
|
||||
return db.none(sql, [couponId])
|
||||
return db.none(sql, [id])
|
||||
}
|
||||
|
||||
function getNumberOfAvailableCoupons () {
|
||||
function getNumberOfAvailablePromoCodes () {
|
||||
const sql = `SELECT COUNT(id) FROM coupons WHERE soft_deleted=false`
|
||||
return db.one(sql).then(res => res.count)
|
||||
}
|
||||
|
||||
module.exports = { getAvailableCoupons, getCoupon, createCoupon, deleteCoupon, getNumberOfAvailableCoupons }
|
||||
module.exports = { getAvailablePromoCodes, getPromoCode, createPromoCode, deletePromoCode, getNumberOfAvailablePromoCodes }
|
||||
|
|
@ -25,7 +25,7 @@ const E = require('./error')
|
|||
const customers = require('./customers')
|
||||
const logs = require('./logs')
|
||||
const compliance = require('./compliance')
|
||||
const couponManager = require('./coupons')
|
||||
const promoCodes = require('./promo-codes')
|
||||
const BN = require('./bn')
|
||||
const commissionMath = require('./commission-math')
|
||||
|
||||
|
|
@ -216,15 +216,15 @@ function verifyTx (req, res, next) {
|
|||
.catch(next)
|
||||
}
|
||||
|
||||
function verifyCoupon (req, res, next) {
|
||||
couponManager.getCoupon(req.body.codeInput)
|
||||
.then(coupon => {
|
||||
if (!coupon) return next()
|
||||
function verifyPromoCode (req, res, next) {
|
||||
promoCodes.getPromoCode(req.body.codeInput)
|
||||
.then(promoCode => {
|
||||
if (!promoCode) 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 = commissionMath.getDiscountRate(coupon.discount, commissions[transaction.direction])
|
||||
const discount = commissionMath.getDiscountRate(promoCode.discount, commissions[transaction.direction])
|
||||
const rates = {
|
||||
[transaction.cryptoCode]: {
|
||||
[transaction.direction]: (transaction.direction === 'cashIn')
|
||||
|
|
@ -234,7 +234,7 @@ function verifyCoupon (req, res, next) {
|
|||
}
|
||||
|
||||
respond(req, res, {
|
||||
coupon: coupon,
|
||||
promoCode: promoCode,
|
||||
newRates: rates
|
||||
})
|
||||
})
|
||||
|
|
@ -479,7 +479,7 @@ const configRequiredRoutes = [
|
|||
'/phone_code',
|
||||
'/customer',
|
||||
'/tx',
|
||||
'/verify_coupon'
|
||||
'/verify_promo_code'
|
||||
]
|
||||
|
||||
const app = express()
|
||||
|
|
@ -506,7 +506,7 @@ app.post('/state', stateChange)
|
|||
|
||||
app.post('/verify_user', verifyUser)
|
||||
app.post('/verify_transaction', verifyTx)
|
||||
app.post('/verify_coupon', verifyCoupon)
|
||||
app.post('/verify_promo_code', verifyPromoCode)
|
||||
|
||||
app.post('/phone_code', getCustomerWithPhoneCode)
|
||||
app.patch('/customer/:id', updateCustomer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue