#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -1,6 +1,6 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('machineWorker updateInTime()', () => {
|
||||
describe('machineWorker updateInTime()', () => {
|
||||
const itBoss = 104;
|
||||
const davidCharles = 1106;
|
||||
|
||||
|
@ -65,6 +65,22 @@ fdescribe('machineWorker updateInTime()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should throw an error if it is himself with a different machine', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = itBoss;
|
||||
const plate = 'RE-003';
|
||||
try {
|
||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('You are already using a machine');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should set the out time if it is himself', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
|
|
@ -51,15 +51,19 @@ module.exports = Self => {
|
|||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
||||
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
|
||||
const isHimSelf = userId == machineWorker.workerFk;
|
||||
jorgep marked this conversation as resolved
Outdated
|
||||
const isSameMachine = machine.id == machineWorker.machineFk;
|
||||
|
||||
if (maxHours > hoursDifference && !isHimSelf)
|
||||
if (hoursDifference < maxHours && !isHimSelf)
|
||||
throw new UserError($t('This machine is already in use.'));
|
||||
|
||||
if (hoursDifference < maxHours && isHimSelf && !isSameMachine)
|
||||
throw new UserError($t('You are already using a machine'));
|
||||
|
||||
await machineWorker.updateAttributes({
|
||||
outTime: Date.vnNew()
|
||||
}, myOptions);
|
||||
|
||||
if (maxHours <= hoursDifference)
|
||||
if (hoursDifference >= maxHours)
|
||||
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
|
||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
Si en els dos casos fa el mateix, fica fora de les condicions Si en els dos casos fa el mateix, fica fora de les condicions
|
||||
} else
|
||||
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
|
||||
|
|
|
@ -20,8 +20,8 @@ describe('mobileAppVersionControl getVersion()', () => {
|
|||
});
|
||||
|
||||
it('should get the beta version app', async() => {
|
||||
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
||||
ctx.req.accessToken.userId = 66;
|
||||
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
||||
|
||||
expect(versionBeta).toBeDefined();
|
||||
expect(version).toBeUndefined();
|
||||
|
|
|
@ -207,5 +207,7 @@
|
|||
"This machine is already in use.": "This machine is already in use.",
|
||||
"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"
|
||||
"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"
|
||||
|
||||
}
|
|
@ -344,5 +344,6 @@
|
|||
"the plate does not exist": "La máquina {{plate}} 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",
|
||||
"Esta máquina ya está en uso.": "Esta máquina ya está en uso."
|
||||
"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."
|
||||
}
|
Loading…
Reference in New Issue
isHimself