diff --git a/back/methods/machine-worker/add.js b/back/methods/machine-worker/add.js deleted file mode 100644 index c6fdd620e..000000000 --- a/back/methods/machine-worker/add.js +++ /dev/null @@ -1,57 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('add', { - description: 'Insert log if the worker has not logged anything in the last 12 hours', - accessType: 'READ', - accepts: [ - { - arg: 'plate', - type: 'string', - } - ], - http: { - path: `/add`, - verb: 'POST' - } - }); - - Self.add = async(ctx, plate, options) => { - const models = Self.app.models; - const userId = ctx.req.accessToken.userId; - - let tx; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const machine = await models.Machine.findOne({ - fields: ['id', 'plate'], - where: {plate} - }, myOptions); - - if (!machine) throw new Error(`plate ${plate} does not exist`); - - await models.MachineWorker.updateAll( - { - or: [{workerFk: userId}, {machineFk: machine.id}], - and: [{outTime: null }] - }, - {outTime: Date.vnNew()}, - myOptions - ); - - await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/back/methods/machine-worker/updateInTime.js b/back/methods/machine-worker/updateInTime.js index 0ae968b83..5065373a2 100644 --- a/back/methods/machine-worker/updateInTime.js +++ b/back/methods/machine-worker/updateInTime.js @@ -35,9 +35,8 @@ module.exports = Self => { fields: ['id', 'plate'], where: {plate} }, 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 machineWorker = await Self.findOne({ where: { machineFk: machine.id, @@ -46,10 +45,11 @@ module.exports = Self => { }, myOptions); if (machineWorker) { - const hoursDifference = (Date.vnNew() - machineWorker.inTime) / (60 * 60 * 1000); + const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions); + const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000); const isHimSelf = userId == machineWorker.workerFk; - if (maxHours > hoursDifference && !isHimSelf) throw new UserError('Esta máquina ya está en uso.'); + if (maxHours > hoursDifference && !isHimSelf) throw new UserError('This machine is already in use.'); await machineWorker.updateAttributes({ outTime: Date.vnNew() diff --git a/back/models/machine-worker.js b/back/models/machine-worker.js index b44cb1fb6..cbc5fd53e 100644 --- a/back/models/machine-worker.js +++ b/back/models/machine-worker.js @@ -1,4 +1,3 @@ module.exports = Self => { require('../methods/machine-worker/updateInTime')(Self); - require('../methods/machine-worker/add')(Self); }; diff --git a/db/changes/235001/00-newWareHouse.sql b/db/changes/235001/00-newWareHouse.sql index 60d2658b0..1b1ec263f 100644 --- a/db/changes/235001/00-newWareHouse.sql +++ b/db/changes/235001/00-newWareHouse.sql @@ -3,7 +3,6 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp ('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'employee'), ('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'employee'), ('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','employee'), - ('MachineWorker','add','READ','ALLOW','ROLE','employee'), ('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','employee'), ('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'), ('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee'),