Chore: merge compliance notification code changes
This commit is contained in:
parent
fc39d9b1a3
commit
757db75d1a
7 changed files with 36 additions and 21 deletions
15
lib/respond.js
Normal file
15
lib/respond.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
const _ = require('lodash/fp')
|
||||||
|
const notifier = require('./notifier')
|
||||||
|
|
||||||
|
function respond (req, res, _body, _status) {
|
||||||
|
const status = _status || 200
|
||||||
|
const body = _body || {}
|
||||||
|
const customer = _.getOr({ sanctions: true }, ['customer'], body)
|
||||||
|
// sanctions can be null for new customers so we can't use falsy checks
|
||||||
|
if (customer.sanctions === false) {
|
||||||
|
notifier.notifyIfActive('compliance', 'sanctionsNotify', customer, req.body.phone)
|
||||||
|
}
|
||||||
|
return res.status(status).json(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = respond
|
||||||
|
|
@ -8,6 +8,8 @@ const complianceTriggers = require('../compliance-triggers')
|
||||||
const configManager = require('../new-config-manager')
|
const configManager = require('../new-config-manager')
|
||||||
const customers = require('../customers')
|
const customers = require('../customers')
|
||||||
const httpError = require('../route-helpers').httpError
|
const httpError = require('../route-helpers').httpError
|
||||||
|
const notifier = require('../notifier')
|
||||||
|
const respond = require('../respond')
|
||||||
|
|
||||||
function updateCustomer (req, res, next) {
|
function updateCustomer (req, res, next) {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
|
|
@ -37,7 +39,7 @@ function updateCustomer (req, res, next) {
|
||||||
.then(newPatch => customers.updateFrontCamera(id, newPatch))
|
.then(newPatch => customers.updateFrontCamera(id, newPatch))
|
||||||
.then(newPatch => customers.update(id, newPatch, null, txId))
|
.then(newPatch => customers.update(id, newPatch, null, txId))
|
||||||
})
|
})
|
||||||
.then(customer => res.status(200).json({ customer }))
|
.then(customer => respond(req, res, { customer }))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +52,7 @@ function triggerSanctions (req, res, next) {
|
||||||
return compliance.validationPatch(req.deviceId, true, customer)
|
return compliance.validationPatch(req.deviceId, true, customer)
|
||||||
.then(patch => customers.update(id, patch))
|
.then(patch => customers.update(id, patch))
|
||||||
})
|
})
|
||||||
.then(customer => res.status(200).json({ customer }))
|
.then(customer => respond(req, res, { customer }))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +60,10 @@ function triggerBlock (req, res, next) {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
|
|
||||||
customers.update(id, { authorizedOverride: 'blocked' })
|
customers.update(id, { authorizedOverride: 'blocked' })
|
||||||
.then(customer => res.status(200).json({ customer }))
|
.then(customer => {
|
||||||
|
notifier.notifyIfActive('compliance', 'customerComplianceNotify', customer, req.deviceId, 'BLOCKED')
|
||||||
|
return respond(req, res, { customer })
|
||||||
|
})
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +79,10 @@ function triggerSuspend (req, res, next) {
|
||||||
const date = new Date()
|
const date = new Date()
|
||||||
date.setDate(date.getDate() + days)
|
date.setDate(date.getDate() + days)
|
||||||
customers.update(id, { suspendedUntil: date })
|
customers.update(id, { suspendedUntil: date })
|
||||||
.then(customer => res.status(200).json({ customer }))
|
.then(customer => {
|
||||||
|
notifier.notifyIfActive('compliance', 'customerComplianceNotify', customer, req.deviceId, 'SUSPENDED', days)
|
||||||
|
return respond(req, res, { customer })
|
||||||
|
})
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ const customers = require('../customers')
|
||||||
const httpError = require('../route-helpers').httpError
|
const httpError = require('../route-helpers').httpError
|
||||||
const plugins = require('../plugins')
|
const plugins = require('../plugins')
|
||||||
const Tx = require('../tx')
|
const Tx = require('../tx')
|
||||||
|
const respond = require('../respond')
|
||||||
|
|
||||||
function addOrUpdateCustomer (req) {
|
function addOrUpdateCustomer (req) {
|
||||||
const customerData = req.body
|
const customerData = req.body
|
||||||
|
|
@ -52,7 +53,7 @@ function getCustomerWithPhoneCode (req, res, next) {
|
||||||
return pi.getPhoneCode(phone)
|
return pi.getPhoneCode(phone)
|
||||||
.then(code => {
|
.then(code => {
|
||||||
return addOrUpdateCustomer(req)
|
return addOrUpdateCustomer(req)
|
||||||
.then(customer => res.status(200).json({ code, customer }))
|
.then(customer => respond(req, res, { code, customer }))
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.name === 'BadNumberError') throw httpError('Bad number', 401)
|
if (err.name === 'BadNumberError') throw httpError('Bad number', 401)
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@ const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
const helpers = require('../route-helpers')
|
const helpers = require('../route-helpers')
|
||||||
|
const respond = require('../respond')
|
||||||
|
|
||||||
function stateChange (req, res, next) {
|
function stateChange (req, res, next) {
|
||||||
helpers.stateChange(req.deviceId, req.deviceTime, req.body)
|
helpers.stateChange(req.deviceId, req.deviceTime, req.body)
|
||||||
.then(() => res.status(200).json({}))
|
.then(() => respond(req, res))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,11 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const _ = require('lodash/fp')
|
|
||||||
|
|
||||||
const BN = require('../bn')
|
const BN = require('../bn')
|
||||||
const commissionMath = require('../commission-math')
|
const commissionMath = require('../commission-math')
|
||||||
const configManager = require('../new-config-manager')
|
const configManager = require('../new-config-manager')
|
||||||
const notifier = require('../notifier')
|
|
||||||
const promoCodes = require('../promo-codes')
|
const promoCodes = require('../promo-codes')
|
||||||
|
const respond = require('../respond')
|
||||||
function respond (req, res, _body, _status) {
|
|
||||||
const status = _status || 200
|
|
||||||
const body = _body || {}
|
|
||||||
const customer = _.getOr({ sanctions: true }, ['customer'], body)
|
|
||||||
// sanctions can be null for new customers so we can't use falsy checks
|
|
||||||
if (customer.sanctions === false) {
|
|
||||||
notifier.notifyIfActive('compliance', 'sanctionsNotify', customer, req.body.phone)
|
|
||||||
}
|
|
||||||
return res.status(status).json(body)
|
|
||||||
}
|
|
||||||
|
|
||||||
function verifyPromoCode (req, res, next) {
|
function verifyPromoCode (req, res, next) {
|
||||||
promoCodes.getPromoCode(req.body.codeInput)
|
promoCodes.getPromoCode(req.body.codeInput)
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
const plugins = require('../plugins')
|
const plugins = require('../plugins')
|
||||||
|
const respond = require('../respond')
|
||||||
|
|
||||||
function verifyTx (req, res, next) {
|
function verifyTx (req, res, next) {
|
||||||
const pi = plugins(req.settings, req.deviceId)
|
const pi = plugins(req.settings, req.deviceId)
|
||||||
pi.verifyTransaction(req.body)
|
pi.verifyTransaction(req.body)
|
||||||
.then(idResult => res.status(200).json(idResult))
|
.then(idResult => respond(req, res, idResult))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
const plugins = require('../plugins')
|
const plugins = require('../plugins')
|
||||||
|
const respond = require('../respond')
|
||||||
|
|
||||||
function verifyUser (req, res, next) {
|
function verifyUser (req, res, next) {
|
||||||
const pi = plugins(req.settings, req.deviceId)
|
const pi = plugins(req.settings, req.deviceId)
|
||||||
pi.verifyUser(req.body)
|
pi.verifyUser(req.body)
|
||||||
.then(idResult => res.status(200).json(idResult))
|
.then(idResult => respond(req, res, idResult))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue