Add *override_by fields in customer
This commit is contained in:
parent
e351d1b495
commit
89eb617a4a
3 changed files with 39 additions and 3 deletions
|
|
@ -194,7 +194,8 @@ app.get('/api/customer/:id', (req, res, next) => {
|
||||||
*/
|
*/
|
||||||
app.patch('/api/customer/:id', (req, res, next) => {
|
app.patch('/api/customer/:id', (req, res, next) => {
|
||||||
if (!req.params.id) return res.status(400).send({Error: 'Requires id'})
|
if (!req.params.id) return res.status(400).send({Error: 'Requires id'})
|
||||||
return customers.update(req.params.id, req.query)
|
const token = req.token || req.cookies.token
|
||||||
|
return customers.update(req.params.id, req.query, token)
|
||||||
.then(r => res.send(r))
|
.then(r => res.send(r))
|
||||||
.catch(() => res.status(404).send({Error: 'Not found'}))
|
.catch(() => res.status(404).send({Error: 'Not found'}))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,13 @@ function get (phone) {
|
||||||
*
|
*
|
||||||
* @param {string} id Customer's id
|
* @param {string} id Customer's id
|
||||||
* @param {object} data Fields to update
|
* @param {object} data Fields to update
|
||||||
|
* @param {string} Acting user's token
|
||||||
|
*
|
||||||
* @returns {Promise} Newly updated Customer
|
* @returns {Promise} Newly updated Customer
|
||||||
*/
|
*/
|
||||||
function update (id, data) {
|
function update (id, data, userToken) {
|
||||||
const updateData = _.omit(['id'], _.mapKeys(_.snakeCase, data))
|
const formattedData = _.omit(['id'], _.mapKeys(_.snakeCase, data))
|
||||||
|
const updateData = addOverrideUser(formattedData, userToken)
|
||||||
const sql = Pgp.helpers.update(updateData, _.keys(updateData), 'customers') +
|
const sql = Pgp.helpers.update(updateData, _.keys(updateData), 'customers') +
|
||||||
' where id=$1 returning *'
|
' where id=$1 returning *'
|
||||||
return db.oneOrNone(sql, [id])
|
return db.oneOrNone(sql, [id])
|
||||||
|
|
@ -60,6 +63,32 @@ function getDailyVolume (id) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add *override_by fields with acting user's token
|
||||||
|
*
|
||||||
|
* @name addOverrideUser
|
||||||
|
* @function
|
||||||
|
*
|
||||||
|
* @param {object} customer Customer's object to add the fields
|
||||||
|
* @param {string} userToken Acting user's token
|
||||||
|
* @returns {object} Customer populated with *_by fields
|
||||||
|
*/
|
||||||
|
function addOverrideUser (customer, userToken) {
|
||||||
|
if (!userToken) return customer
|
||||||
|
// Overrode fields
|
||||||
|
const overrideFields = [
|
||||||
|
'sms_override',
|
||||||
|
'id_card_data_override',
|
||||||
|
'id_card_photo_override',
|
||||||
|
'front_facing_cam_override',
|
||||||
|
'sanctions_check_override',
|
||||||
|
'authorized_override' ]
|
||||||
|
overrideFields.forEach(field => {
|
||||||
|
if (customer[field]) customer[field + '_by'] = userToken
|
||||||
|
})
|
||||||
|
return customer
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format and populate fields
|
* Format and populate fields
|
||||||
* for customer record
|
* for customer record
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,17 @@ exports.up = function (next) {
|
||||||
|
|
||||||
'alter table customers drop column manually_verified ',
|
'alter table customers drop column manually_verified ',
|
||||||
"alter table customers add column sms_override verification_type not null default 'automatic'",
|
"alter table customers add column sms_override verification_type not null default 'automatic'",
|
||||||
|
'alter table customers add column sms_override_by references user_tokens (token)',
|
||||||
"alter table customers add column id_card_data_override verification_type not null default 'automatic'",
|
"alter table customers add column id_card_data_override verification_type not null default 'automatic'",
|
||||||
|
'alter table customers add column id_card_data_override_by references user_tokens (token)',
|
||||||
"alter table customers add column id_card_photo_override verification_type not null default 'automatic'",
|
"alter table customers add column id_card_photo_override verification_type not null default 'automatic'",
|
||||||
|
'alter table customers add column id_card_photo_override_by references user_tokens (token)',
|
||||||
"alter table customers add column front_facing_cam_override verification_type not null default 'automatic'",
|
"alter table customers add column front_facing_cam_override verification_type not null default 'automatic'",
|
||||||
|
'alter table customers add column front_facing_cam_override_by references user_tokens (token)',
|
||||||
"alter table customers add column sanctions_check_override verification_type not null default 'automatic'",
|
"alter table customers add column sanctions_check_override verification_type not null default 'automatic'",
|
||||||
|
'alter table customers add column sanctions_check_override_by references user_tokens (token)',
|
||||||
"alter table customers add column authorized_override verification_type not null default 'automatic'",
|
"alter table customers add column authorized_override verification_type not null default 'automatic'",
|
||||||
|
'alter table customers add column authorized_override_by references user_tokens (token)',
|
||||||
'alter table customers add column authorized_at timestamptz',
|
'alter table customers add column authorized_at timestamptz',
|
||||||
'alter table customers add column sanctions_check_at timestamptz',
|
'alter table customers add column sanctions_check_at timestamptz',
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue