salix/modules/route/back/methods/roadmapStop/getPalletMatchState.js

63 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-06-03 16:39:11 +00:00
module.exports = Self => {
Self.remoteMethod('getPalletMatchState', {
2024-07-02 10:03:21 +00:00
description: 'Get list of pallet from truckFk with true or false if state is matched',
2024-06-03 16:39:11 +00:00
accessType: 'WRITE',
accepts: [{
2024-07-02 10:03:21 +00:00
arg: 'truckFk',
2024-06-03 16:39:11 +00:00
type: 'number',
required: true,
2024-07-02 10:03:21 +00:00
description: 'The truckFk id'
2024-06-03 16:39:11 +00:00
},
{
arg: 'state',
type: 'string',
required: true,
description: 'State code'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getPalletMatchState`,
verb: 'GET'
}
});
2024-07-02 10:03:21 +00:00
Self.getPalletMatchState = async(truckFk, state, options) => {
2024-06-03 16:39:11 +00:00
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const result = await Self.rawSql(`
WITH tPallet AS(
2024-07-02 06:39:42 +00:00
SELECT ep.id pallet, e.id expedition, e.stateTypeFk
FROM vn.expeditionPallet ep
2024-06-03 16:39:11 +00:00
JOIN vn.expeditionScan es ON es.palletFk = ep.id
JOIN expedition e ON e.id = es.expeditionFk
2024-06-03 16:39:11 +00:00
WHERE ep.truckFk = ?
),totalPalletExpedition AS(
SELECT t.*, COUNT(expedition) totalPalletExpedition
FROM tPallet t
GROUP BY expedition
),totalPalletExpeditionCode AS(
SELECT t.*, COUNT(expedition) totalPalletExpeditionCode
FROM tPallet t
JOIN vn.expeditionStateType est ON est.id = t.stateTypeFk
2024-06-03 16:39:11 +00:00
WHERE code = ?
GROUP BY expedition
)
SELECT t.pallet,
2024-07-02 06:39:42 +00:00
tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode hasMatchStateCode
2024-06-03 16:39:11 +00:00
FROM tPallet t
LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition
LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition
GROUP BY t.pallet;`,
2024-07-02 10:03:21 +00:00
[truckFk, state],
2024-06-03 16:39:11 +00:00
myOptions);
return result;
};
};