feat: refs #7134 use filter to order by
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-12-27 13:57:28 +01:00
parent 3691daded4
commit a69a767c8a
1 changed files with 20 additions and 1 deletions

View File

@ -1,11 +1,17 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const {buildFilter, mergeFilters} = require('vn-loopback/util/filter');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('receipts', { Self.remoteMethodCtx('receipts', {
description: 'Find all clients matched by the filter', description: 'Find all clients matched by the filter',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
{ {
arg: 'filter',
type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'}
}, {
arg: 'supplierId', arg: 'supplierId',
type: 'number', type: 'number',
description: 'The supplier id', description: 'The supplier id',
@ -21,6 +27,12 @@ module.exports = Self => {
description: 'The currency', description: 'The currency',
default: 1, default: 1,
}, },
{
arg: 'bankFk',
type: 'number',
description: 'The bank',
default: 1,
},
{ {
arg: 'orderBy', arg: 'orderBy',
type: 'string', type: 'string',
@ -50,7 +62,12 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'bankFk':
return {'bankFk': value};
}
});
let stmts = []; let stmts = [];
stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [ stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [
args.supplierId, args.supplierId,
@ -63,6 +80,8 @@ module.exports = Self => {
const stmt = new ParameterizedSQL(` const stmt = new ParameterizedSQL(`
SELECT * SELECT *
FROM tmp.supplierStatement`); FROM tmp.supplierStatement`);
filter = mergeFilters(args.filter, {where});
stmt.merge(conn.makeSuffix(filter)); stmt.merge(conn.makeSuffix(filter));
stmts.push(stmt); stmts.push(stmt);
stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`); stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`);