feat: refs #7950 Modified sql
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2024-11-11 11:16:57 +01:00
parent 1bacc3d03b
commit 5a33f0d4f2
1 changed files with 60 additions and 40 deletions

View File

@ -3,7 +3,7 @@ const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters; const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('cmrs', { Self.remoteMethodCtx('cmrs', {
description: 'Returns an array of cmrs', description: 'Returns an array of cmrs',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
@ -15,42 +15,37 @@ module.exports = Self => {
{ {
arg: 'cmrFk', arg: 'cmrFk',
type: 'integer', type: 'integer',
description: 'Searchs the route by id', description: 'Searchs the cmr by id',
}, },
{ {
arg: 'ticketFk', arg: 'sender',
type: 'integer',
description: 'The worker id',
},
{
arg: 'routeFk',
type: 'integer',
description: 'The route id',
},
{
arg: 'country',
type: 'string', type: 'string',
description: 'The agencyMode id', description: 'The sender code',
}, },
{ {
arg: 'clientFk', arg: 'loadingPlace',
type: 'integer', type: 'string',
description: 'The vehicle id',
}, },
{ {
arg: 'hasCmrDms', arg: 'deliveryPlace',
type: 'boolean', type: 'string',
description: 'The vehicle id',
}, },
{ {
arg: 'shipped', arg: 'carrier',
type: 'string',
},
{
arg: 'loadingDate',
type: 'date', type: 'date',
description: 'The to date filter',
}, },
{ {
arg: 'warehouseFk', arg: 'landingDate',
type: 'integer', type: 'date',
} },
{
arg: 'truckPlate',
type: 'string',
},
], ],
returns: { returns: {
type: ['object'], type: ['object'],
@ -62,23 +57,48 @@ module.exports = Self => {
} }
}); });
Self.cmrs = async( Self.cmrs = async(ctx, filter) => {
filter, cmrFk, ticketFk, routeFk, country, clientFk, hasCmrDms, shipped, warehouseFk, options
) => {
const params = {cmrFk, ticketFk, routeFk, country, clientFk, hasCmrDms, warehouseFk, shipped};
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
let loadingDateTo = ctx.args.loadingDate;
let where = buildFilter(params, (param, value) => { if (loadingDateTo) {
return {[param]: value}; loadingDateTo = new Date(loadingDateTo);
}); loadingDateTo.setHours(23, 59, 59, 999);
filter = mergeFilters(filter, {where});
if (!filter.where) {
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
filter.where = {'shipped': yesterday.toISOString().split('T')[0]};
} }
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'cmrFk':
return {'c.id': value};
case 'sender':
return {'co.code': {like: `%${value}%`}};
case 'loadingPlace':
return {'af.nickname': {like: `%${value}%`}};
case 'deliveryPlace':
return {'at.nickname': {like: `%${value}%`}};
case 'carrier':
return {'s.name': {like: `%${value}%`}};
case 'loadingDate':
return {
'c.created': {
between: [value, loadingDateTo]
}
};
case 'landingDate':
return {'c.ead': value};
case 'truckPlate':
return {'c.truckPlate': {like: `%${value}%`}};
case 'm3':
case 'warehouseFk':
case 'workerFk':
case 'vehicleFk':
case 'agencyModeFk':
return {[param]: value};
}
});
filter = mergeFilters(filter, {where});
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
@ -86,7 +106,7 @@ module.exports = Self => {
let stmts = []; let stmts = [];
const stmt = new ParameterizedSQL(` const stmt = new ParameterizedSQL(`
SELECT c.id, SELECT c.id cmrFk,
co.code sender, co.code sender,
af.nickname loadingPlace, af.nickname loadingPlace,
at.nickname deliveryPlace, at.nickname deliveryPlace,
@ -100,7 +120,7 @@ module.exports = Self => {
c.specialAgreements, c.specialAgreements,
c.paymentInstruccions, c.paymentInstruccions,
c.observations, c.observations,
t.id t.id ticketFk
FROM cmr c FROM cmr c
JOIN address af ON af.id = c.addressFromFk JOIN address af ON af.id = c.addressFromFk
JOIN address at ON at.id = c.addressToFk JOIN address at ON at.id = c.addressToFk