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

54 lines
1.3 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',
},
});
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};
}
};
};