Patch Customer with authorized_verified status
This commit is contained in:
parent
e347ddc608
commit
3623e41302
3 changed files with 424 additions and 98 deletions
|
|
@ -183,6 +183,26 @@ app.get('/api/customer/:id', (req, res, next) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint for patching customer's authorized_override status
|
||||||
|
*
|
||||||
|
* Possible values: blocked, verified, automatic
|
||||||
|
*
|
||||||
|
* @param {string} '/api/customer/ Url to handle
|
||||||
|
* @param {object} req Request object
|
||||||
|
* @param {object} res Response object
|
||||||
|
* @param {function} next Callback
|
||||||
|
*/
|
||||||
|
app.patch('/api/customer/:id', (req, res, next) => {
|
||||||
|
if (!req.query.authorized_override) return res.status(400).send({Error: 'Requires authorized'})
|
||||||
|
|
||||||
|
return customers.patch(req.params.id, {
|
||||||
|
authorized_override: req.query.authorized_override
|
||||||
|
})
|
||||||
|
.then(r => res.send(r))
|
||||||
|
.catch(() => res.status(404).send({Error: 'Not found'}))
|
||||||
|
})
|
||||||
|
|
||||||
app.use((err, req, res, next) => {
|
app.use((err, req, res, next) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,19 @@ function get (phone) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Patch Customer
|
||||||
|
* Note: Currently patching only authorized_verified field
|
||||||
|
*
|
||||||
|
* @param {string} id Customer's id
|
||||||
|
* @param {object} values Values to patch
|
||||||
|
* @returns {object} Updated customer
|
||||||
|
*/
|
||||||
|
function patch (id, values) {
|
||||||
|
const sql = 'update customers set authorized_override=$2 where id=$1 returning *'
|
||||||
|
return db.oneOrNone(sql, [id, values.authorized_override])
|
||||||
|
}
|
||||||
|
|
||||||
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])
|
||||||
|
|
@ -65,4 +78,4 @@ function batch () {
|
||||||
order by created desc limit $2`
|
order by created desc limit $2`
|
||||||
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ])
|
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ])
|
||||||
}
|
}
|
||||||
module.exports = { add, get, batch, getById }
|
module.exports = { add, get, batch, getById, patch}
|
||||||
|
|
|
||||||
487
public/elm.js
487
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