Update Customer's data
This commit is contained in:
parent
9877fc8ef0
commit
94de659246
3 changed files with 534 additions and 104 deletions
|
|
@ -29,6 +29,7 @@ const server = require('./server')
|
||||||
const transactions = require('./transactions')
|
const transactions = require('./transactions')
|
||||||
const customers = require('../customers')
|
const customers = require('../customers')
|
||||||
const funding = require('./funding')
|
const funding = require('./funding')
|
||||||
|
const _ = require('lodash/fp')
|
||||||
|
|
||||||
const NEVER = new Date(Date.now() + 100 * T.years)
|
const NEVER = new Date(Date.now() + 100 * T.years)
|
||||||
const REAUTHENTICATE_INTERVAL = T.minute
|
const REAUTHENTICATE_INTERVAL = T.minute
|
||||||
|
|
@ -184,9 +185,7 @@ app.get('/api/customer/:id', (req, res, next) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Endpoint for patching customer's authorizedOverride status
|
* Endpoint for patching customer's data
|
||||||
*
|
|
||||||
* Possible values: blocked, verified, automatic
|
|
||||||
*
|
*
|
||||||
* @param {string} '/api/customer/ Url to handle
|
* @param {string} '/api/customer/ Url to handle
|
||||||
* @param {object} req Request object
|
* @param {object} req Request object
|
||||||
|
|
@ -194,11 +193,8 @@ app.get('/api/customer/:id', (req, res, next) => {
|
||||||
* @param {function} next Callback
|
* @param {function} next Callback
|
||||||
*/
|
*/
|
||||||
app.patch('/api/customer/:id', (req, res, next) => {
|
app.patch('/api/customer/:id', (req, res, next) => {
|
||||||
if (!req.query.authorizedOverride) return res.status(400).send({Error: 'Requires authorized'})
|
if (!req.params.id) return res.status(400).send({Error: 'Requires id'})
|
||||||
|
return customers.update(req.params.id, req.query)
|
||||||
return customers.patch(req.params.id, {
|
|
||||||
authorizedOverride: req.query.authorizedOverride
|
|
||||||
})
|
|
||||||
.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'}))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ const BN = require('./bn')
|
||||||
const anonymous = require('../lib/constants').anonymousCustomer
|
const anonymous = require('../lib/constants').anonymousCustomer
|
||||||
const NUM_RESULTS = 20
|
const NUM_RESULTS = 20
|
||||||
const camelize = require('camelize')
|
const camelize = require('camelize')
|
||||||
|
const Pgp = require('pg-promise')()
|
||||||
|
|
||||||
function add (customer) {
|
function add (customer) {
|
||||||
const sql = 'insert into customers (id, phone, phone_at) values ($1, $2, now()) returning *'
|
const sql = 'insert into customers (id, phone, phone_at) values ($1, $2, now()) returning *'
|
||||||
|
|
@ -23,24 +24,27 @@ function get (phone) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patch Customer
|
* Update customer record
|
||||||
* Note: Currently patching only authorized_verified field
|
*
|
||||||
|
* @name update
|
||||||
|
* @function
|
||||||
*
|
*
|
||||||
* @param {string} id Customer's id
|
* @param {string} id Customer's id
|
||||||
* @param {object} values Values to patch
|
* @param {object} data Fields to update
|
||||||
* @returns {object} Updated customer
|
* @returns {Promise} Newly updated Customer
|
||||||
*/
|
*/
|
||||||
function patch (id, values) {
|
function update (id, data) {
|
||||||
const sql = 'update customers set authorized_override=$2 where id=$1 returning *'
|
const updateData = _.omit(['id'], _.mapKeys(_.snakeCase, data))
|
||||||
return db.oneOrNone(sql, [id, values.authorizedOverride])
|
const sql = Pgp.helpers.update(updateData, _.keys(updateData), 'customers') +
|
||||||
|
' where id=$1 returning *'
|
||||||
|
return db.oneOrNone(sql, [id])
|
||||||
|
.then(customer => customer ? format(customer) : null)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getById (id) {
|
function getById (id) {
|
||||||
const sql = 'select * from customers where id=$1'
|
const sql = 'select * from customers where id=$1'
|
||||||
return db.oneOrNone(sql, [id])
|
return db.oneOrNone(sql, [id])
|
||||||
.then(customer => {
|
.then(customer => customer ? format(customer) : null)
|
||||||
return (customer) ? format(customer) : null
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDailyVolume (id) {
|
function getDailyVolume (id) {
|
||||||
|
|
@ -104,4 +108,4 @@ function batch () {
|
||||||
.then(_.map(format))
|
.then(_.map(format))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { add, get, batch, getById, patch}
|
module.exports = { add, get, batch, getById, update}
|
||||||
|
|
|
||||||
600
public/elm.js
600
public/elm.js
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue