Add comments

This commit is contained in:
goga-m 2017-10-12 18:19:18 +03:00 committed by Josh Harvey
parent 932be9e7db
commit a731ec7a03
3 changed files with 62 additions and 0 deletions

View file

@ -11,11 +11,32 @@ const users = require('./users')
const NUM_RESULTS = 20
/**
* Add new customer
*
* @name add
* @function
*
* @param {object} Customer object (with phone number)
*
* @returns {object} Newly created customer
*/
function add (customer) {
const sql = 'insert into customers (id, phone, phone_at) values ($1, $2, now()) returning *'
return db.one(sql, [uuid.v4(), customer.phone])
}
/**
* Get single customer by phone
* Phone numbers are unique per customer
*
* @name get
* @function
*
* @param {string} phone Customer's phone number
*
* @returns {object} Customer
*/
function get (phone) {
const sql = 'select * from customers where phone=$1'
return db.oneOrNone(sql, [phone])
@ -48,6 +69,17 @@ function update (id, data, userToken) {
.then(camelize)
}
/**
* Get customer by id
*
* @name getById
* @function
*
* @param {string} id Customer's unique id
* @param {string} userToken Acting user's token
*
* @returns {object} Customer found
*/
function getById (id, userToken) {
const sql = 'select * from customers where id=$1'
return db.oneOrNone(sql, [id])