refs #5995 Requested changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2023-08-10 08:12:52 +02:00
parent ed88a5b25f
commit d6b30271f2
1 changed files with 21 additions and 11 deletions

View File

@ -3,7 +3,7 @@ const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethodCtx('getExternalCmrs', {
Self.remoteMethod('getExternalCmrs', {
description: 'Returns an array of external cmrs',
accessType: 'READ',
accepts: [
@ -11,43 +11,36 @@ 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: 'cmrFk',
type: 'integer',
description: 'Searchs the route by id',
http: {source: 'query'}
},
{
arg: 'ticketFk',
type: 'integer',
description: 'The worker id',
http: {source: 'query'}
},
{
arg: 'country',
type: 'string',
description: 'The agencyMode id',
http: {source: 'query'}
},
{
arg: 'clientFk',
type: 'integer',
description: 'The vehicle id',
http: {source: 'query'}
},
{
arg: 'hasCmrDms',
type: 'boolean',
description: 'The vehicle id',
http: {source: 'query'}
},
{
arg: 'shipped',
type: 'date',
description: 'The to date filter',
http: {source: 'query'}
},
],
returns: {
@ -60,10 +53,27 @@ module.exports = Self => {
}
});
Self.getExternalCmrs = async(ctx, filter, options) => {
Self.getExternalCmrs = async(
filter,
cmrFk,
ticketFk,
country,
clientFk,
hasCmrDms,
shipped,
options
) => {
const params = {
cmrFk,
ticketFk,
country,
clientFk,
hasCmrDms,
shipped,
};
const conn = Self.dataSource.connector;
let where = buildFilter(ctx.args, (param, value) => {
let where = buildFilter(params, (param, value) => {
switch (param) {
case 'cmrFk':
return {'cmrFk': value};
@ -80,7 +90,7 @@ module.exports = Self => {
}
});
filter = mergeFilters(ctx.args.filter, {where});
filter = mergeFilters(filter, {where});
if (!filter.where) {
const yesterday = new Date();