7152-devToTest_2414 #2228

Merged
alexm merged 636 commits from 7152-devToTest_2414 into test 2024-03-28 08:26:34 +00:00
4 changed files with 45 additions and 7 deletions
Showing only changes of commit e69ec2c856 - Show all commits

View File

@ -204,5 +204,6 @@
"The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified",
"It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}", "It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}",
"Incorrect pin": "Incorrect pin.", "Incorrect pin": "Incorrect pin.",
"The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified" "This machine is already in use.": "This machine is already in use.",
"This pallet does not exist": "This pallet does not exist"
} }

View File

@ -340,6 +340,6 @@
"No tickets to invoice": "No hay tickets para facturar", "No tickets to invoice": "No hay tickets para facturar",
"No hay tickets para sacar": "No hay tickets para sacar", "No hay tickets para sacar": "No hay tickets para sacar",
"There is no zone for these parameters 999999": "There is no zone for these parameters 999999", "There is no zone for these parameters 999999": "There is no zone for these parameters 999999",
"Esta máquina ya está en uso.": "Esta máquina ya está en uso.", "This machine is already in use.": "Esta máquina ya está en uso.",
"This machine is already in use.": "This machine is already in use." "This pallet does not exist": "Este palet no existe"
} }

View File

@ -1,7 +1,7 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('getPallet', { Self.remoteMethodCtx('getPallet', {
description: 'Get pallet', description: 'Get pallet',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
@ -20,7 +20,13 @@ module.exports = Self => {
}, },
}); });
Self.getPallet = async expeditionFk => { Self.getPallet = async(ctx, expeditionFk, options) => {
const myOptions = {};
const $t = ctx.req.__;
if (typeof options == 'object')
Object.assign(myOptions, options);
try { try {
const pallet = await Self.findOne({ const pallet = await Self.findOne({
fields: ['truckFk'], fields: ['truckFk'],
@ -35,7 +41,7 @@ module.exports = Self => {
} }
} }
], ],
}); }, myOptions);
if (pallet) { if (pallet) {
const truck = pallet.expeditionTruck(); const truck = pallet.expeditionTruck();
@ -46,7 +52,7 @@ module.exports = Self => {
}; };
} }
throw new UserError('palletDoesNotExist'); throw new UserError($t('This pallet does not exist'));
} catch (e) { } catch (e) {
return {message: e.message}; return {message: e.message};
} }

View File

@ -0,0 +1,31 @@
const {models} = require('vn-loopback/server/server');
fdescribe('expeditonPallet getPallet()', () => {
beforeAll(async() => {
ctx = {
accessToken: {userId: 9},
req: {
headers: {origin: 'http://localhost'},
__: value => value
}
};
});
it('should obtain the pallet data', async() => {
const pallet = await models.ExpeditionPallet.getPallet(ctx, 1);
expect(pallet).toBeDefined();
expect(pallet.truckFk).toEqual(1);
expect(pallet.description).toEqual('BEST TRUCK IN FLEET');
});
it('should throw an error when the pallet does not exist', async() => {
try {
await models.ExpeditionPallet.getPallet(ctx, 1);
} catch (e) {
const error = e;
expect(error.message).toEqual('This pallet does not exist');
}
});
});