chore: undo $ prepend on queries

This commit is contained in:
Taranto 2021-07-22 11:06:39 +01:00 committed by Josh Harvey
parent f3f2bb01b0
commit ba4117173e
50 changed files with 215 additions and 227 deletions

View file

@ -34,7 +34,7 @@ const operatorDataDir = _.get('operatorDataDir', options)
*/
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])
return db.one(sql, [uuid.v4(), customer.phone])
.then(populateOverrideUsernames)
.then(computeStatus)
.then(populateDailyVolume)
@ -54,7 +54,7 @@ function add (customer) {
*/
function get (phone) {
const sql = 'select * from customers where phone=$1'
return db.$oneOrNone(sql, [phone])
return db.oneOrNone(sql, [phone])
.then(populateDailyVolume)
.then(camelize)
}
@ -80,7 +80,7 @@ function update (id, data, userToken, txId) {
const sql = Pgp.helpers.update(updateData, _.keys(updateData), 'customers') +
' where id=$1 returning *'
return db.$one(sql, [id])
return db.one(sql, [id])
.then(addComplianceOverrides(id, updateData, userToken))
.then(populateOverrideUsernames)
.then(computeStatus)
@ -120,7 +120,7 @@ async function updateCustomer (id, data, userToken) {
' where id=$1'
invalidateCustomerNotifications(id, formattedData)
await db.$none(sql, [id])
await db.none(sql, [id])
return getCustomerById(id)
}
@ -145,7 +145,7 @@ const invalidateCustomerNotifications = (id, data) => {
*/
function getById (id, userToken) {
const sql = 'select * from customers where id=$1'
return db.$oneOrNone(sql, [id])
return db.oneOrNone(sql, [id])
.then(populateOverrideUsernames)
.then(computeStatus)
.then(populateDailyVolume)
@ -174,10 +174,10 @@ function getDailyVolume (id, txId) {
function getDailyVolumeQueries (id) {
return [
db.$one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
where customer_id=$1
and created > now() - interval '1 day'`, [id]),
db.$one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
where customer_id=$1
and created > now() - interval '1 day'`, [id])
]
@ -185,11 +185,11 @@ function getDailyVolumeQueries (id) {
function getDailyVolumeMinusCurrentTxQueries (id, txId) {
return [
db.$one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_in_txs
where customer_id=$1
and id!=$2
and created > now() - interval '1 day'`, [id, txId]),
db.$one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
db.one(`select coalesce(sum(fiat), 0) as total, max(created) as maxdate from cash_out_txs
where customer_id=$1
and id!=$2
and created > now() - interval '1 day'`, [id, txId])
@ -432,7 +432,7 @@ function batch () {
const sql = `select * from customers
where id != $1
order by created desc limit $2`
return db.$any(sql, [ anonymous.uuid, NUM_RESULTS ])
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ])
.then(customers => Promise.all(_.map(customer => {
return populateOverrideUsernames(customer)
.then(computeStatus)
@ -475,7 +475,7 @@ function getCustomersList () {
where c.id != $1
) as cl where rn = 1
limit $2`
return db.$any(sql, [ anonymous.uuid, NUM_RESULTS ])
return db.any(sql, [ anonymous.uuid, NUM_RESULTS ])
.then(customers => Promise.all(_.map(customer => {
return populateOverrideUsernames(customer)
.then(camelize)
@ -513,7 +513,7 @@ function getCustomerById (id) {
from cash_out_txs where confirmed_at is not null) t on c.id = t.customer_id
where c.id = $1
) as cl where rn = 1`
return db.$oneOrNone(sql, [id])
return db.oneOrNone(sql, [id])
.then(populateOverrideUsernames)
.then(camelize)
}