fix customer query

pull/1/head
Aji Kamaludin 3 years ago
parent 18efaff50c
commit b3227d5658
No known key found for this signature in database
GPG Key ID: 670E1F26AD5A8099

@ -14,7 +14,7 @@ class CustomersService {
FROM customers
WHERE
company_id = '${companyId}'
${q !== null ? `AND name ILIKE '%${q}%'` : ''}
${q ? `AND (name ILIKE '%${q}%' OR phone ILIKE '%${q}%')` : ''}
`);
const { total } = recordsQuery.rows[0];
@ -27,12 +27,14 @@ class CustomersService {
SELECT id, name, phone, description
FROM customers
WHERE company_id = $1
${q !== null ? `AND name ILIKE '%${q}%' OR phone ILIKE '%${q}%'` : ''}
${q ? `AND (name ILIKE '%${q}%' OR phone ILIKE '%${q}%')` : ''}
ORDER BY created_at DESC
LIMIT $2 OFFSET $3`,
values: [companyId, limit, offsets],
};
console.log(query.text)
const { rows } = await this._pool.query(query);
return {

@ -2,7 +2,7 @@ const Joi = require('joi');
const PostCustomerPayloadSchema = Joi.object({
name: Joi.string().required(),
phone: Joi.string().allow(''),
phone: Joi.number().allow(''),
address: Joi.string().allow(''),
description: Joi.string().allow(''),
});

Loading…
Cancel
Save