Provide Daily Volume in customer's api
This commit is contained in:
parent
67dda25b20
commit
932be9e7db
2 changed files with 131 additions and 71 deletions
|
|
@ -19,13 +19,8 @@ function add (customer) {
|
|||
function get (phone) {
|
||||
const sql = 'select * from customers where phone=$1'
|
||||
return db.oneOrNone(sql, [phone])
|
||||
.then(customer => {
|
||||
if (!customer) return
|
||||
return getDailyVolume(customer.id).then(dailyVolume => {
|
||||
const formatted = camelize(customer)
|
||||
return _.set('dailyVolume', dailyVolume, formatted)
|
||||
})
|
||||
})
|
||||
.then(populateDailyVolume)
|
||||
.then(camelize)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -49,6 +44,7 @@ function update (id, data, userToken) {
|
|||
.then(addComplianceOverrides(id, updateData, userToken))
|
||||
.then(populateOverrideUsernames)
|
||||
.then(computeStatus)
|
||||
.then(populateDailyVolume)
|
||||
.then(camelize)
|
||||
}
|
||||
|
||||
|
|
@ -57,9 +53,20 @@ function getById (id, userToken) {
|
|||
return db.oneOrNone(sql, [id])
|
||||
.then(populateOverrideUsernames)
|
||||
.then(computeStatus)
|
||||
.then(populateDailyVolume)
|
||||
.then(camelize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and calculate customer's daily volume
|
||||
* for both cash_in & cash_out txs
|
||||
*
|
||||
* @name getDailyVolume
|
||||
* @function
|
||||
*
|
||||
* @param {string} id Customer's id
|
||||
* @returns {Bignumber} Customer's daily volume
|
||||
*/
|
||||
function getDailyVolume (id) {
|
||||
return Promise.all([
|
||||
db.one(`select coalesce(sum(fiat), 0) as total from cash_in_txs
|
||||
|
|
@ -73,6 +80,23 @@ function getDailyVolume (id) {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate customer object
|
||||
* with dailyVolume information
|
||||
*
|
||||
* @name populateDailyVolume
|
||||
* @function
|
||||
*
|
||||
* @param {object} customer Customer object
|
||||
* @returns {object} Customer object populated with dailyVolume
|
||||
*/
|
||||
function populateDailyVolume (customer) {
|
||||
if (!customer) return
|
||||
return getDailyVolume(customer.id).then(dailyVolume => {
|
||||
return _.set('daily_volume', dailyVolume, customer)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available complianceTypes
|
||||
* that can be overriden (excluding hard_limit)
|
||||
|
|
@ -236,6 +260,7 @@ function batch () {
|
|||
.then(customers => Promise.all(_.map(customer => {
|
||||
return populateOverrideUsernames(customer)
|
||||
.then(computeStatus)
|
||||
.then(populateDailyVolume)
|
||||
.then(camelize)
|
||||
}, customers)))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue