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 _ = require('lodash/fp')
const BN = require('./bn') const BN = require('./bn')
const anonymous = require('../lib/constants').anonymousCustomer const anonymous = require('../lib/constants').anonymousCustomer
const NUM_RESULTS = 20
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 *'
@ -34,8 +35,10 @@ function getDailyVolume (id) {
} }
function batch () { function batch () {
const sql = `select * from customers where id not in ($1)` const sql = `select * from customers
return db.any(sql, [anonymous.uuid]) where id != $1
order by created desc limit $2`
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ])
} }
module.exports = { add, get, batch } module.exports = { add, get, batch }

View file

@ -31964,12 +31964,12 @@ var _user$project$Common_Customer_Decoder$customerDecoder = A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$optional, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$optional,
'phone', 'phone',
_elm_lang$core$Json_Decode$string, _elm_lang$core$Json_Decode$string,
'--', '',
A4( A4(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$optional, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$optional,
'name', 'name',
_elm_lang$core$Json_Decode$string, _elm_lang$core$Json_Decode$string,
'--', '',
A3( A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'id', 'id',