Add sort and limit in customers batch
This commit is contained in:
parent
69ae1401a3
commit
ebc346c6ae
2 changed files with 7 additions and 4 deletions
|
|
@ -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 }
|
||||||
|
|
|
||||||
|
|
@ -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',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue