refs #6694 perf: update postCode/filter method
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
725c43c7e4
commit
5d53d69754
|
@ -7,10 +7,6 @@ module.exports = Self => {
|
||||||
description:
|
description:
|
||||||
'Find all postcodes of the model matched by postcode, town, province or country.',
|
'Find all postcodes of the model matched by postcode, town, province or country.',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
returns: {
|
|
||||||
type: ['object'],
|
|
||||||
root: true,
|
|
||||||
},
|
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
|
@ -25,6 +21,10 @@ module.exports = Self => {
|
||||||
http: {source: 'query'}
|
http: {source: 'query'}
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true,
|
||||||
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/filter`,
|
path: `/filter`,
|
||||||
verb: 'GET',
|
verb: 'GET',
|
||||||
|
@ -32,12 +32,11 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
Self.filter = async(ctx, filter, options) => {
|
Self.filter = async(ctx, filter, options) => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
const where = buildFilter(ctx.args, (param, value) => {
|
const where = buildFilter(ctx.where, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'search':
|
case 'search':
|
||||||
return {or: [
|
return {or: [
|
||||||
|
@ -50,7 +49,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}) ?? {};
|
}) ?? {};
|
||||||
|
|
||||||
filter = mergeFilters(ctx.args?.filter ?? {}, {where});
|
filter = mergeFilters(ctx?.where ?? {}, where);
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
@ -67,7 +66,7 @@ module.exports = Self => {
|
||||||
JOIN country c on c.id = p.countryFk
|
JOIN country c on c.id = p.countryFk
|
||||||
`);
|
`);
|
||||||
|
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
stmt.merge(conn.makeSuffix({where: filter, limit: ctx?.limit ?? 30}));
|
||||||
const itemsIndex = stmts.push(stmt) - 1;
|
const itemsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
|
Loading…
Reference in New Issue