fix: dynamic query
This commit is contained in:
parent
03fd19e0cf
commit
43ff04b2af
1 changed files with 2 additions and 2 deletions
|
|
@ -78,9 +78,9 @@ function getCustomersWithDiscounts (discounts) {
|
||||||
const idCardNumbersSql = _.map(pgp.as.text, idCardNumbers).join(',')
|
const idCardNumbersSql = _.map(pgp.as.text, idCardNumbers).join(',')
|
||||||
|
|
||||||
const hasPhoneNumbers = !_.isEmpty(phoneNumbers)
|
const hasPhoneNumbers = !_.isEmpty(phoneNumbers)
|
||||||
const hasIDNumbers = !_.isEmpty(phoneNumbers)
|
const hasIDNumbers = !_.isEmpty(idCardNumbers)
|
||||||
|
|
||||||
const sql = `SELECT * FROM customers WHERE ${hasPhoneNumbers && `phone IN ($1^)`} ${hasPhoneNumbers && hasIDNumbers && `OR`} ${hasIDNumbers && `id_card_data_number IN ($2^)`}`
|
const sql = `SELECT * FROM customers WHERE ${hasPhoneNumbers ? `phone IN ($1^)` : ``} ${hasPhoneNumbers && hasIDNumbers ? `OR` : ``} ${hasIDNumbers ? `id_card_data_number IN ($2^)` : ``}`
|
||||||
return db.any(sql, [phoneNumbersSql, idCardNumbersSql])
|
return db.any(sql, [phoneNumbersSql, idCardNumbersSql])
|
||||||
.then(res => _.map(it => it ? _.mapKeys(_.camelCase, it) : null, res))
|
.then(res => _.map(it => it ? _.mapKeys(_.camelCase, it) : null, res))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue