Add comments
This commit is contained in:
parent
932be9e7db
commit
a731ec7a03
3 changed files with 62 additions and 0 deletions
|
|
@ -1,6 +1,16 @@
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
const uuid = require('uuid')
|
const uuid = require('uuid')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new compliance override
|
||||||
|
*
|
||||||
|
* @name add
|
||||||
|
* @function
|
||||||
|
*
|
||||||
|
* @param {object} complianceOverride Compliance override object
|
||||||
|
*
|
||||||
|
* @returns {object} Newly created compliance override
|
||||||
|
*/
|
||||||
function add (complianceOverride) {
|
function add (complianceOverride) {
|
||||||
const sql = `insert into compliance_overrides
|
const sql = `insert into compliance_overrides
|
||||||
(id,
|
(id,
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,32 @@ const users = require('./users')
|
||||||
|
|
||||||
const NUM_RESULTS = 20
|
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) {
|
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 *'
|
||||||
return db.one(sql, [uuid.v4(), customer.phone])
|
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) {
|
function get (phone) {
|
||||||
const sql = 'select * from customers where phone=$1'
|
const sql = 'select * from customers where phone=$1'
|
||||||
return db.oneOrNone(sql, [phone])
|
return db.oneOrNone(sql, [phone])
|
||||||
|
|
@ -48,6 +69,17 @@ function update (id, data, userToken) {
|
||||||
.then(camelize)
|
.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) {
|
function getById (id, userToken) {
|
||||||
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])
|
||||||
|
|
|
||||||
20
lib/users.js
20
lib/users.js
|
|
@ -3,11 +3,31 @@ const pgp = require('pg-promise')()
|
||||||
|
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user by token
|
||||||
|
*
|
||||||
|
* @name get
|
||||||
|
* @function
|
||||||
|
*
|
||||||
|
* @param {string} token User's token to query by
|
||||||
|
*
|
||||||
|
* @returns {user object} User object (containing name)
|
||||||
|
*/
|
||||||
function get (token) {
|
function get (token) {
|
||||||
const sql = 'select * from user_tokens where token=$1'
|
const sql = 'select * from user_tokens where token=$1'
|
||||||
return db.oneOrNone(sql, [token])
|
return db.oneOrNone(sql, [token])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get multiple users given an array of tokens
|
||||||
|
*
|
||||||
|
* @name getByIds
|
||||||
|
* @function
|
||||||
|
*
|
||||||
|
* @param {array} tokens Array with users' tokens
|
||||||
|
*
|
||||||
|
* @returns {array} Array of users found
|
||||||
|
*/
|
||||||
function getByIds (tokens) {
|
function getByIds (tokens) {
|
||||||
const sql = 'select * from user_tokens where token in ($1^)'
|
const sql = 'select * from user_tokens where token in ($1^)'
|
||||||
const tokensClause = _.map(pgp.as.text, tokens).join(',')
|
const tokensClause = _.map(pgp.as.text, tokens).join(',')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue