#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -1,3 +1,4 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('updateInTime', {
|
Self.remoteMethodCtx('updateInTime', {
|
||||||
description: 'Updates the corresponding registry if the worker has been registered in the last few hours',
|
description: 'Updates the corresponding registry if the worker has been registered in the last few hours',
|
||||||
|
@ -34,25 +35,29 @@ module.exports = Self => {
|
||||||
fields: ['id', 'plate'],
|
fields: ['id', 'plate'],
|
||||||
where: {plate}
|
where: {plate}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (!machine) throw new Error(`plate ${plate} does not exist`);
|
if (!machine) throw new Error(`plate ${plate} does not exist`);
|
||||||
|
|
||||||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
||||||
|
const machineWorker = await Self.findOne({
|
||||||
const machineWorker = await models.MachineWorker.findOne({
|
|
||||||
where: {
|
where: {
|
||||||
workerFk: userId,
|
|
||||||
inTime: {gte: Date.vnNew() - (maxHours * 60 * 60 * 1000)},
|
|
||||||
outTimed: null,
|
|
||||||
machineFk: machine.id,
|
machineFk: machine.id,
|
||||||
|
outTime: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
if (machineWorker) {
|
|
||||||
await machineWorker.updateAttributes({
|
|
||||||
outTime: Date.now()
|
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
|
||||||
|
if (machineWorker) {
|
||||||
|
const hoursDifference = (Date.vnNew() - machineWorker.inTime) / (60 * 60 * 1000);
|
||||||
|
const isHimSelf = userId == machineWorker.workerFk;
|
||||||
|
|
||||||
|
if (maxHours > hoursDifference && !isHimSelf) throw new UserError('Esta máquina ya está en uso.');
|
||||||
|
|
||||||
jorgep marked this conversation as resolved
Outdated
|
|||||||
|
await machineWorker.updateAttributes({
|
||||||
|
outTime: Date.vnNew()
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (!isHimSelf) await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
|
||||||
|
} else
|
||||||
|
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -339,5 +339,6 @@
|
||||||
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
||||||
"No tickets to invoice": "No hay tickets para facturar",
|
"No tickets to invoice": "No hay tickets para facturar",
|
||||||
jorgep marked this conversation as resolved
Outdated
jgallego
commented
no puede estar en castellano no puede estar en castellano
|
|||||||
"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."
|
||||||
}
|
}
|
Loading…
Reference in New Issue
isHimself