61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
|
|
const UserError = require('vn-loopback/util/user-error');
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('getPallet', {
|
|
description: 'Get pallet',
|
|
accessType: 'READ',
|
|
accepts: [
|
|
{
|
|
arg: 'expeditionFk',
|
|
type: 'integer',
|
|
},
|
|
],
|
|
http: {
|
|
path: `/getPallet`,
|
|
verb: 'GET'
|
|
},
|
|
returns: {
|
|
type: 'object',
|
|
root: true
|
|
},
|
|
});
|
|
|
|
Self.getPallet = async(ctx, expeditionFk, options) => {
|
|
const myOptions = {};
|
|
const $t = ctx.req.__;
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
try {
|
|
const pallet = await Self.findOne({
|
|
fields: ['truckFk'],
|
|
where: {
|
|
id: expeditionFk
|
|
},
|
|
include: [
|
|
{
|
|
relation: 'expeditionTruck',
|
|
scope: {
|
|
fields: ['eta', 'description']
|
|
}
|
|
}
|
|
],
|
|
}, myOptions);
|
|
|
|
if (pallet) {
|
|
const truck = pallet.expeditionTruck();
|
|
return {
|
|
truckFk: pallet.truckFk,
|
|
eta: truck.eta,
|
|
description: truck.description
|
|
};
|
|
}
|
|
|
|
throw new UserError($t('This pallet does not exist'));
|
|
} catch (e) {
|
|
return {message: e.message};
|
|
}
|
|
};
|
|
};
|