salix/modules/ticket/back/methods/expedition-pallet/getPallet.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-11-21 11:32:36 +00:00
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('getPallet', {
description: 'Get pallet',
accessType: 'READ',
accepts: [
{
arg: 'expeditionFk',
type: 'integer',
},
],
http: {
path: `/getPallet`,
verb: 'GET'
},
returns: {
type: 'object',
2024-01-03 11:50:53 +00:00
root: true
2023-11-21 11:32:36 +00:00
},
});
Self.getPallet = async expeditionFk => {
try {
const pallet = await Self.findOne({
fields: ['truckFk'],
where: {
id: expeditionFk
},
include: [
{
relation: 'expeditionTruck',
scope: {
fields: ['eta', 'description']
}
}
],
});
if (pallet) {
const truck = pallet.expeditionTruck();
return {
truckFk: pallet.truckFk,
eta: truck.eta,
description: truck.description
};
}
throw new UserError('palletDoesNotExist');
} catch (e) {
return {message: e.message};
}
};
};