feat: add search functionality to customer page

This commit is contained in:
Sérgio Salgado 2021-05-31 15:58:24 +01:00 committed by Josh Harvey
parent b99f98982b
commit 2b93f016ac
7 changed files with 151 additions and 24 deletions

View file

@ -27,4 +27,15 @@ function transaction() {
return db.any(sql)
}
module.exports = { transaction }
function customer() {
const sql = `select distinct * from (
select 'phone' as type, phone as value from customers where phone is not null union
select 'name' as type, concat(id_card_data::json->>'firstName', ' ', id_card_data::json->>'lastName') as value from customers where concat(id_card_data::json->>'firstName', ' ', id_card_data::json->>'lastName') is not null union
select 'address' as type, id_card_data::json->>'address' as value from customers where id_card_data::json->>'address' is not null union
select 'id' as type, id_card_data::json->>'documentNumber' as value from customers where id_card_data::json->>'documentNumber' is not null
) f`
return db.any(sql)
}
module.exports = { transaction, customer }