7152-devToTest_2414 #2228
|
@ -37,27 +37,16 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (!machine) throw new Error(`plate ${plate} does not exist`);
|
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(
|
await models.MachineWorker.updateAll(
|
||||||
{or: [{workerFk: userId}, {machineFk: machine.id}]},
|
{
|
||||||
|
or: [{workerFk: userId}, {machineFk: machine.id}],
|
||||||
|
and: [{outTime: null }]
|
||||||
|
},
|
||||||
{outTime: Date.vnNew()},
|
{outTime: Date.vnNew()},
|
||||||
myOptions
|
myOptions
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue