From a731ec7a031fa135c40eca4f00ee63d7ed24c360 Mon Sep 17 00:00:00 2001 From: goga-m Date: Thu, 12 Oct 2017 18:19:18 +0300 Subject: [PATCH] Add comments --- lib/compliance_overrides.js | 10 ++++++++++ lib/customers.js | 32 ++++++++++++++++++++++++++++++++ lib/users.js | 20 ++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/lib/compliance_overrides.js b/lib/compliance_overrides.js index 3dce29a6..f84fe0d1 100644 --- a/lib/compliance_overrides.js +++ b/lib/compliance_overrides.js @@ -1,6 +1,16 @@ const db = require('./db') 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) { const sql = `insert into compliance_overrides (id, diff --git a/lib/customers.js b/lib/customers.js index 4be96d89..5b7719af 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -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]) diff --git a/lib/users.js b/lib/users.js index 3e0153a7..38df45f7 100644 --- a/lib/users.js +++ b/lib/users.js @@ -3,11 +3,31 @@ const pgp = require('pg-promise')() 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) { const sql = 'select * from user_tokens where token=$1' 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) { const sql = 'select * from user_tokens where token in ($1^)' const tokensClause = _.map(pgp.as.text, tokens).join(',')