fix: refs #7679 postcode filter
This commit is contained in:
parent
5264d6c973
commit
434dfe4ae4
|
@ -11,13 +11,11 @@ module.exports = Self => {
|
|||
arg: 'filter',
|
||||
type: 'object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'search',
|
||||
type: 'string',
|
||||
description: 'Value to filter',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
|
@ -29,13 +27,11 @@ module.exports = Self => {
|
|||
verb: 'GET',
|
||||
},
|
||||
});
|
||||
Self.filter = async(ctx, filter, options) => {
|
||||
Self.filter = async(filter = {}, search, options) => {
|
||||
const myOptions = {};
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
filter = ctx?.filter ?? {};
|
||||
|
||||
const conn = Self.dataSource.connector;
|
||||
const where = buildFilter(filter?.where, (param, value) => {
|
||||
switch (param) {
|
||||
|
@ -50,27 +46,27 @@ module.exports = Self => {
|
|||
};
|
||||
}
|
||||
}) ?? {};
|
||||
delete ctx.filter.where;
|
||||
delete filter.where;
|
||||
|
||||
const stmts = [];
|
||||
let stmt;
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT
|
||||
pc.townFk,
|
||||
t.provinceFk,
|
||||
p.countryFk,
|
||||
pc.code,
|
||||
t.name as town,
|
||||
p.name as province,
|
||||
c.name country
|
||||
FROM
|
||||
postCode pc
|
||||
JOIN town t on t.id = pc.townFk
|
||||
JOIN province p on p.id = t.provinceFk
|
||||
JOIN country c on c.id = p.countryFk
|
||||
SELECT
|
||||
pc.townFk,
|
||||
t.provinceFk,
|
||||
p.countryFk,
|
||||
pc.code,
|
||||
t.name as town,
|
||||
p.name as province,
|
||||
c.name country
|
||||
FROM
|
||||
postCode pc
|
||||
JOIN town t on t.id = pc.townFk
|
||||
JOIN province p on p.id = t.provinceFk
|
||||
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 sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
|
|
@ -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 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 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"
|
||||
}
|
Loading…
Reference in New Issue