Add sort and limit in customers batch

This commit is contained in:
goga-m 2017-09-19 19:15:39 +03:00 committed by Josh Harvey
parent 69ae1401a3
commit ebc346c6ae
2 changed files with 7 additions and 4 deletions

View file

@ -3,6 +3,7 @@ const uuid = require('uuid')
const _ = require('lodash/fp')
const BN = require('./bn')
const anonymous = require('../lib/constants').anonymousCustomer
const NUM_RESULTS = 20
function add (customer) {
const sql = 'insert into customers (id, phone, phone_at) values ($1, $2, now()) returning *'
@ -34,8 +35,10 @@ function getDailyVolume (id) {
}
function batch () {
const sql = `select * from customers where id not in ($1)`
return db.any(sql, [anonymous.uuid])
const sql = `select * from customers
where id != $1
order by created desc limit $2`
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ])
}
module.exports = { add, get, batch }