feat: refs #7002 update direction if it was not manual
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
7bf950306b
commit
6ded14b593
|
@ -41,26 +41,24 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const timeEntry = await Self.findById(timeEntryId, null, myOptions);
|
const {id, userFk, timed, manual} = await Self.findById(timeEntryId, null, myOptions);
|
||||||
const isSubordinate = await models.Worker.isSubordinate(ctx, timeEntry.userFk, myOptions);
|
const isSubordinate = await models.Worker.isSubordinate(ctx, userFk, myOptions);
|
||||||
const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE');
|
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);
|
const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss);
|
||||||
if (notAllowed) throw new UserError(`You don't have enough privileges`);
|
if (notAllowed) throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
let timeEntryUpdatedId;
|
await models.WorkerTimeControl.deleteById(id, myOptions);
|
||||||
if (timeEntry.device) {
|
const {id: newTimeEntryId} = await Self.clockIn(
|
||||||
timeEntry.updateAttribute('direction', direction);
|
userFk, timed, direction, null, myOptions
|
||||||
timeEntryUpdatedId = timeEntry.id;
|
);
|
||||||
} else {
|
|
||||||
await models.WorkerTimeControl.deleteById(timeEntry.id, myOptions);
|
if (!manual) await Self.updateAll({id: newTimeEntryId}, {manual: false}, myOptions);
|
||||||
timeEntryUpdatedId = await Self.clockIn(timeEntry.userFk, timeEntry.timed, direction, null, myOptions);
|
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, userFk, timed, myOptions);
|
||||||
}
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, timeEntry.userFk, timeEntry.timed, myOptions);
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
return timeEntryUpdatedId;
|
return newTimeEntryId;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue