fix: refs #6276 machineWorker_add
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-01-09 11:22:11 +01:00
parent ab1dc7af55
commit 9afc3840c7
1 changed files with 6 additions and 17 deletions

View File

@ -37,27 +37,16 @@ module.exports = Self => {
if (!machine) throw new Error(`plate ${plate} does not exist`);
const twelveHoursAgo = Date.vnNew();
twelveHoursAgo.setHours(twelveHoursAgo.getHours() - 12);
const isRegistered = await models.MachineWorker.findOne({
where: {
and: [
{machineFk: machine.id},
{workerFk: userId},
{outTime: {gte: twelveHoursAgo}}
]
}
}, myOptions);
if (!isRegistered) await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
else {
await models.MachineWorker.updateAll(
{or: [{workerFk: userId}, {machineFk: machine.id}]},
{
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) {