fix: refs #7679 postcode filter

This commit is contained in:
Alex Moreno 2024-07-29 15:03:40 +02:00
parent 5264d6c973
commit 434dfe4ae4
2 changed files with 19 additions and 21 deletions

View File

@ -11,13 +11,11 @@ module.exports = Self => {
arg: 'filter', arg: 'filter',
type: 'object', type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'}
}, },
{ {
arg: 'search', arg: 'search',
type: 'string', type: 'string',
description: 'Value to filter', description: 'Value to filter',
http: {source: 'query'}
}, },
], ],
returns: { returns: {
@ -29,13 +27,11 @@ module.exports = Self => {
verb: 'GET', verb: 'GET',
}, },
}); });
Self.filter = async(ctx, filter, options) => { Self.filter = async(filter = {}, search, options) => {
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
filter = ctx?.filter ?? {};
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const where = buildFilter(filter?.where, (param, value) => { const where = buildFilter(filter?.where, (param, value) => {
switch (param) { switch (param) {
@ -50,27 +46,27 @@ module.exports = Self => {
}; };
} }
}) ?? {}; }) ?? {};
delete ctx.filter.where; delete filter.where;
const stmts = []; const stmts = [];
let stmt; let stmt;
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`
SELECT SELECT
pc.townFk, pc.townFk,
t.provinceFk, t.provinceFk,
p.countryFk, p.countryFk,
pc.code, pc.code,
t.name as town, t.name as town,
p.name as province, p.name as province,
c.name country c.name country
FROM FROM
postCode pc postCode pc
JOIN town t on t.id = pc.townFk JOIN town t on t.id = pc.townFk
JOIN province p on p.id = t.provinceFk JOIN province p on p.id = t.provinceFk
JOIN country c on c.id = p.countryFk JOIN country c on c.id = p.countryFk
`); `);
stmt.merge(conn.makeSuffix({where, ...ctx})); stmt.merge(conn.makeSuffix({where}));
const itemsIndex = stmts.push(stmt) - 1; const itemsIndex = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';'); const sql = ParameterizedSQL.join(stmts, ';');

View File

@ -233,5 +233,7 @@
"It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated", "It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated",
"It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated", "It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated",
"Cannot add holidays on this day": "Cannot add holidays on this day", "Cannot add holidays on this day": "Cannot add holidays on this day",
"Cannot send mail": "Cannot send mail" "Cannot send mail": "Cannot send mail",
"CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`",
"This postcode already exists": "This postcode already exists"
} }