#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
await Self.create({
|
||||
jorgep marked this conversation as resolved
Outdated
jgallego
commented
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?
jorgep
commented
@jgallego para dar un error personalizado. @jgallego para dar un error personalizado.
jgallego
commented
@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'));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
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ú.