From ebc346c6ae0205c063badee22eda63f1642ff744 Mon Sep 17 00:00:00 2001 From: goga-m Date: Tue, 19 Sep 2017 19:15:39 +0300 Subject: [PATCH] Add sort and limit in customers batch --- lib/customers.js | 7 +++++-- public/elm.js | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/customers.js b/lib/customers.js index 8e41977b..aab977d7 100644 --- a/lib/customers.js +++ b/lib/customers.js @@ -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 } diff --git a/public/elm.js b/public/elm.js index 8dba2054..d916731a 100644 --- a/public/elm.js +++ b/public/elm.js @@ -31964,12 +31964,12 @@ var _user$project$Common_Customer_Decoder$customerDecoder = A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$optional, 'phone', _elm_lang$core$Json_Decode$string, - '--', + '', A4( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$optional, 'name', _elm_lang$core$Json_Decode$string, - '--', + '', A3( _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required, 'id',