7152-devToTest_2414 #2228
|
@ -208,6 +208,6 @@
|
||||||
"the plate does not exist": "The plate {{plate}} does not exist",
|
"the plate does not exist": "The plate {{plate}} does not exist",
|
||||||
"This pallet does not exist": "This pallet 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",
|
"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",
|
"This pallet does not exist": "Este palet no existe",
|
||||||
"We do not have availability for the selected item": "No tenemos disponible el item seleccionado",
|
"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.",
|
"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 => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('add', {
|
Self.remoteMethodCtx('add', {
|
||||||
description: 'Add a new operator',
|
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 userId = ctx.req.accessToken.userId;
|
||||||
const user = await Self.findById(userId);
|
const myOptions = {};
|
||||||
if (!user) {
|
const $t = ctx.req.__;
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await Self.create({
|
await Self.create({
|
||||||
workerFk: userId
|
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