refs #5995 Added getExternalCmrs #1703

Merged
guillermo merged 5 commits from 5995-liliumExternalCmr into master 2023-08-10 08:35:29 +00:00
1 changed files with 21 additions and 11 deletions
Showing only changes of commit d6b30271f2 - Show all commits

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 => {
}
});
Review

no es necesario el switch, ya que contiene todos los parámetros

no es necesario el switch, ya que contiene todos los parámetros
filter = mergeFilters(ctx.args.filter, {where});
filter = mergeFilters(filter, {where});
if (!filter.where) {
const yesterday = new Date();