feat: roadMap refs #7195
This commit is contained in:
parent
b9a9f52514
commit
882d5bf036
|
@ -0,0 +1,63 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getPalletMatchState', {
|
||||
description: 'Get pallet',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'roadMapStopFk',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The roadmapFk id'
|
||||
},
|
||||
{
|
||||
arg: 'state',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'State code'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getPalletMatchState`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getPalletMatchState = async(roadMapStopFk, state, options) => {
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const result = await Self.rawSql(`
|
||||
WITH tPallet AS(
|
||||
SELECT ep.truckFk roadMapStop,ep.id pallet, e.id expedition, e.stateTypeFk
|
||||
FROM vn.expeditionPallet ep
|
||||
JOIN vn.expeditionScan es ON es.palletFk = ep.id
|
||||
JOIN expedition e ON e.id = es.expeditionFk
|
||||
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
|
||||
WHERE code = ?
|
||||
GROUP BY expedition
|
||||
)
|
||||
SELECT t.roadMapStop,
|
||||
t.pallet,
|
||||
IF (tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode, 'TRUE', 'FALSE') hasMatchStateCode
|
||||
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;`,
|
||||
[roadMapStopFk, state],
|
||||
myOptions);
|
||||
|
||||
return result;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('roadMapStop getPalletMatchState()', () => {
|
||||
fit('should return list of pallet with true or false if state is matched', async() => {
|
||||
const roadmapStopFk = 1;
|
||||
const state = 'ON DELIVERY';
|
||||
const result = await models.RoadmapStop.getPalletMatchState(roadmapStopFk, state);
|
||||
|
||||
expect(result[0].hasMatchStateCode).toBe('TRUE');
|
||||
});
|
||||
});
|
|
@ -41,6 +41,18 @@
|
|||
},
|
||||
"driverName": {
|
||||
"type": "string"
|
||||
},
|
||||
"kmStart": {
|
||||
"type": "number"
|
||||
},
|
||||
"kmEnd": {
|
||||
"type": "number"
|
||||
},
|
||||
"started": {
|
||||
"type": "date"
|
||||
},
|
||||
"finished": {
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/roadmapStop/getPalletMatchState')(Self);
|
||||
};
|
Loading…
Reference in New Issue