fix: refs #7129 fix filter

This commit is contained in:
Pablo Natek 2024-07-22 06:41:02 +02:00
parent fd2bac713d
commit ae18a52a89
1 changed files with 40 additions and 38 deletions

View File

@ -91,25 +91,23 @@ module.exports = Self => {
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'search':
return {'r.id': value};
return {'id': value};
case 'from':
return {'r.created': {gte: value}};
return {'created': {gte: value}};
case 'to':
return {'r.created': {lte: value}};
return {'created': {lte: value}};
case 'm3':
return {'r.m3': value};
return {'m3': value};
case 'description':
return {'r.description': {like: `%${value}%`}};
return {'description': {like: `%${value}%`}};
case 'warehouseFk':
param = `v.${param}`;
param = `${param}`;
return {[param]: value};
case 'workerFk':
case 'vehicleFk':
case 'agencyModeFk':
param = `r.${param}`;
param = `${param}`;
return {[param]: value};
case 'isOk':
return {'r.isOk': value};
return {'isOk': value};
}
});
@ -119,34 +117,38 @@ module.exports = Self => {
let stmt;
stmt = new ParameterizedSQL(
`SELECT
r.id,
r.workerFk,
r.created,
r.vehicleFk,
r.agencyModeFk,
r.time,
r.isOk,
r.kmStart,
r.kmEnd,
r.started,
r.finished,
r.gestdocFk,
r.cost,
r.m3,
r.description,
am.name agencyName,
u.name AS workerUserName,
v.numberPlate AS vehiclePlateNumber,
Date_format(r.time, '%H:%i') hour,
eu.email
FROM route r
LEFT JOIN agencyMode am ON am.id = r.agencyModeFk
LEFT JOIN agency a ON a.id = am.agencyFk
LEFT JOIN vehicle v ON v.id = r.vehicleFk
LEFT JOIN worker w ON w.id = r.workerFk
LEFT JOIN account.user u ON u.id = w.id
LEFT JOIN account.emailUser eu ON eu.userFk = r.workerFk`
`SELECT *
FROM(
SELECT
r.id,
r.workerFk,
r.created,
r.vehicleFk,
r.agencyModeFk,
r.time,
r.isOk,
r.kmStart,
r.kmEnd,
r.started,
r.finished,
r.gestdocFk,
r.cost,
r.m3,
r.description,
am.name agencyName,
u.name workerUserName,
v.numberPlate vehiclePlateNumber,
Date_format(r.time, '%H:%i') hour,
eu.email,
v.warehouseFk
FROM route r
LEFT JOIN agencyMode am ON am.id = r.agencyModeFk
LEFT JOIN agency a ON a.id = am.agencyFk
LEFT JOIN vehicle v ON v.id = r.vehicleFk
LEFT JOIN worker w ON w.id = r.workerFk
LEFT JOIN account.user u ON u.id = w.id
LEFT JOIN account.emailUser eu ON eu.userFk = r.workerFk
) sub`
);
stmt.merge(conn.makeSuffix(filter));