#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
4 changed files with 51 additions and 6 deletions
Showing only changes of commit 817a6b1289 - Show all commits

View File

@ -208,6 +208,6 @@
"the plate does not exist": "The plate {{plate}} does not exist",
"This pallet does not exist": "This pallet does not exist",
"We do not have availability for the selected item": "We do not have availability for the selected item",
"You are already using a machine": "You are already using a machine"
"You are already using a machine": "You are already using a machine",
"This worker does not exist": "This worker does not exist"
}

View File

@ -345,5 +345,6 @@
"This pallet does not exist": "Este palet no existe",
"We do not have availability for the selected item": "No tenemos disponible el item seleccionado",
"You are already using a machine": "Ya estás usando una máquina.",
"Ya estás usando una máquina.": "Ya estás usando una máquina."
"This worker does not exist": "Este trabajador no existe",
"Este trabajador no existe": "Este trabajador no existe"
}

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('add', {
description: 'Add a new operator',
@ -8,13 +9,28 @@ module.exports = Self => {
}
});
Self.add = async ctx => {
Self.add = async(ctx, options) => {
const userId = ctx.req.accessToken.userId;
const user = await Self.findById(userId);
if (!user) {
const myOptions = {};
const $t = ctx.req.__;
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
jorgep marked this conversation as resolved Outdated

No sé si esto ya lo hablamos, me suena que sí, pero por asegurar.
Aquí habéis contemplado no crear este método y llamar al create nativo de loopback gestionando el error en caso de que ya exista?

No sé si esto ya lo hablamos, me suena que sí, pero por asegurar. Aquí habéis contemplado no crear este método y llamar al create nativo de loopback gestionando el error en caso de que ya exista?

@jgallego Sí, acabo de hablar con Sergio y hemos quedado en cambiarlo a como dices tú.

@jgallego Sí, acabo de hablar con Sergio y hemos quedado en cambiarlo a como dices tú.
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await Self.create({
jorgep marked this conversation as resolved Outdated

si simplemente se hace el create? porque no lo hace segio usando el put desde front?

si simplemente se hace el create? porque no lo hace segio usando el put desde front?

@jgallego para dar un error personalizado.

@jgallego para dar un error personalizado.

@sergiodt realment es necesita?

@sergiodt realment es necesita?
workerFk: userId
});
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw new UserError($t('This worker does not exist'));
}
};
};

View File

@ -0,0 +1,28 @@
const {models} = require('vn-loopback/server/server');
describe('operator add()', () => {
beforeAll(async() => {
ctx = {
req: {
accessToken: {userId: 100000},
headers: {origin: 'http://localhost'},
__: value => value
}
};
});
it('should throw an error if the worker does not exist', async() => {
const tx = await models.Operator.beginTransaction({});
const options = {transaction: tx};
try {
await models.Operator.add(ctx, options);
await tx.rollback();
} catch (e) {
const error = e;
expect(error.message).toEqual('This worker does not exist');
await tx.rollback();
}
});
});