Prevent compliance from triggering prematurely
This commit is contained in:
parent
09332c37db
commit
18bbfc6def
2 changed files with 12 additions and 8 deletions
|
|
@ -69,7 +69,7 @@ function get (phone) {
|
|||
*
|
||||
* @returns {Promise} Newly updated Customer
|
||||
*/
|
||||
function update (id, data, userToken) {
|
||||
function update (id, data, userToken, txId) {
|
||||
const formattedData = _.omit(['id'], _.mapKeys(_.snakeCase, data))
|
||||
|
||||
const updateData = enhanceAtFields(enhanceOverrideFields(formattedData, userToken))
|
||||
|
|
@ -81,7 +81,7 @@ function update (id, data, userToken) {
|
|||
.then(addComplianceOverrides(id, updateData, userToken))
|
||||
.then(populateOverrideUsernames)
|
||||
.then(computeStatus)
|
||||
.then(populateDailyVolume)
|
||||
.then((it) => populateDailyVolume(it, txId))
|
||||
.then(camelize)
|
||||
}
|
||||
|
||||
|
|
@ -113,16 +113,19 @@ function getById (id, userToken) {
|
|||
* @function
|
||||
*
|
||||
* @param {string} id Customer's id
|
||||
* @param {string} txId current tx, to be ignored in the query
|
||||
* @returns {Bignumber} Customer's daily volume
|
||||
*/
|
||||
function getDailyVolume (id) {
|
||||
function getDailyVolume (id, txId) {
|
||||
return Promise.all([
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
|
||||
where customer_id=$1
|
||||
and created > now() - interval '1 day'`, [id]),
|
||||
${txId ? 'and id!=$2' : ''}
|
||||
and created > now() - interval '1 day'`, [id, txId]),
|
||||
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
|
||||
where customer_id=$1
|
||||
and created > now() - interval '1 day'`, [id])
|
||||
${txId ? 'and id!=$2' : ''}
|
||||
and created > now() - interval '1 day'`, [id, txId])
|
||||
]).then(([cashIn, cashOut]) => {
|
||||
const dailyVolume = BN(cashIn.total).add(cashOut.total)
|
||||
const hoursTillLimitClear = getHoursTillLimitClear(cashIn.maxdate, cashOut.maxdate)
|
||||
|
|
@ -167,9 +170,9 @@ function camelize (customer) {
|
|||
* @param {object} customer Customer object
|
||||
* @returns {object} Customer object populated with dailyVolume
|
||||
*/
|
||||
function populateDailyVolume (customer) {
|
||||
function populateDailyVolume (customer, txId) {
|
||||
if (!customer) return
|
||||
return getDailyVolume(customer.id).then(({ dailyVolume, hoursTillLimitClear }) => {
|
||||
return getDailyVolume(customer.id, txId).then(({ dailyVolume, hoursTillLimitClear }) => {
|
||||
let withHours = _.set('hours_till_limit_clear', hoursTillLimitClear, customer)
|
||||
return _.set('daily_volume', dailyVolume, withHours)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue