7167-testToMaster_2414 #2244

Merged
alexm merged 643 commits from 7167-testToMaster_2414 into master 2024-04-04 05:32:41 +00:00
1 changed files with 11 additions and 13 deletions
Showing only changes of commit 6ded14b593 - Show all commits

View File

@ -41,26 +41,24 @@ module.exports = Self => {
}
try {
const timeEntry = await Self.findById(timeEntryId, null, myOptions);
const isSubordinate = await models.Worker.isSubordinate(ctx, timeEntry.userFk, myOptions);
const {id, userFk, timed, manual} = await Self.findById(timeEntryId, null, myOptions);
const isSubordinate = await models.Worker.isSubordinate(ctx, userFk, myOptions);
const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE');
const isHimself = currentUserId == timeEntry.userFk;
const isHimself = currentUserId == userFk;
const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss);
if (notAllowed) throw new UserError(`You don't have enough privileges`);
let timeEntryUpdatedId;
if (timeEntry.device) {
timeEntry.updateAttribute('direction', direction);
timeEntryUpdatedId = timeEntry.id;
} else {
await models.WorkerTimeControl.deleteById(timeEntry.id, myOptions);
timeEntryUpdatedId = await Self.clockIn(timeEntry.userFk, timeEntry.timed, direction, null, myOptions);
}
await models.WorkerTimeControl.deleteById(id, myOptions);
const {id: newTimeEntryId} = await Self.clockIn(
userFk, timed, direction, null, myOptions
);
if (!manual) await Self.updateAll({id: newTimeEntryId}, {manual: false}, myOptions);
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, userFk, timed, myOptions);
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, timeEntry.userFk, timeEntry.timed, myOptions);
if (tx) await tx.commit();
return timeEntryUpdatedId;
return newTimeEntryId;
} catch (e) {
if (tx) await tx.rollback();
throw e;