Add id-card compliance
This commit is contained in:
parent
fbcb8b5ff2
commit
86dfca60c1
6 changed files with 67 additions and 210 deletions
|
|
@ -57,9 +57,12 @@ function get (phone) {
|
|||
*/
|
||||
function update (id, data, userToken) {
|
||||
const formattedData = _.omit(['id'], _.mapKeys(_.snakeCase, data))
|
||||
const updateData = enhanceOverrideFields(formattedData, userToken)
|
||||
|
||||
const updateData = enhanceAtFields(enhanceOverrideFields(formattedData, userToken))
|
||||
|
||||
const sql = Pgp.helpers.update(updateData, _.keys(updateData), 'customers') +
|
||||
' where id=$1 returning *'
|
||||
|
||||
return db.one(sql, [id])
|
||||
.then(addComplianceOverrides(id, updateData, userToken))
|
||||
.then(populateOverrideUsernames)
|
||||
|
|
@ -100,11 +103,11 @@ function getById (id, userToken) {
|
|||
*/
|
||||
function getDailyVolume (id) {
|
||||
return Promise.all([
|
||||
db.one(`select coalesce(sum(fiat), 0) as total from cash_in_txs
|
||||
where customer_id=$1
|
||||
db.one(`select coalesce(sum(fiat), 0) as total from cash_in_txs
|
||||
where customer_id=$1
|
||||
and created > now() - interval '1 day'`, [id]),
|
||||
db.one(`select coalesce(sum(fiat), 0) as total from cash_out_txs
|
||||
where customer_id=$1
|
||||
db.one(`select coalesce(sum(fiat), 0) as total from cash_out_txs
|
||||
where customer_id=$1
|
||||
and created > now() - interval '1 day'`, [id])
|
||||
]).then(([cashInTotal, cashOutTotal]) => {
|
||||
return BN(cashInTotal.total).add(cashOutTotal.total)
|
||||
|
|
@ -161,6 +164,21 @@ function getComplianceTypes () {
|
|||
'authorized' ]
|
||||
}
|
||||
|
||||
function enhanceAtFields (fields) {
|
||||
const updateableFields = [
|
||||
'id_card_data',
|
||||
'id_card_photo',
|
||||
'front_camera',
|
||||
'sanctions',
|
||||
'authorized'
|
||||
]
|
||||
|
||||
const updatedFields = _.intersection(updateableFields, _.keys(fields))
|
||||
const atFields = _.fromPairs(_.map(f => [`${f}_at`, 'now()^'], updatedFields))
|
||||
|
||||
return _.merge(fields, atFields)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add *override_by and *override_at fields with acting user's token
|
||||
* and date of override respectively before saving to db.
|
||||
|
|
@ -298,7 +316,7 @@ function populateOverrideUsernames (customer) {
|
|||
* @returns {array} Array of customers populated with status field
|
||||
*/
|
||||
function batch () {
|
||||
const sql = `select * from customers
|
||||
const sql = `select * from customers
|
||||
where id != $1
|
||||
order by created desc limit $2`
|
||||
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue