fix: hotfix 7323 createAbsence #3265
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Worker','canCreateAbsenceInPast','WRITE','ALLOW','ROLE','hr');
|
|
@ -246,5 +246,5 @@
|
|||
"Payment method is required": "Payment method is required",
|
||||
"The raid information is not correct": "The raid information is not correct",
|
||||
"Sales already moved": "Sales already moved",
|
||||
"There are tickets to be invoiced": "There are tickets to be invoiced for this zone, please delete them first"
|
||||
"Holidays to past days not available": "Holidays to past days not available"
|
||||
}
|
||||
|
|
|
@ -389,5 +389,5 @@
|
|||
"The web user's email already exists": "El correo del usuario web ya existe",
|
||||
"Sales already moved": "Ya han sido transferidas",
|
||||
"The raid information is not correct": "La información de la redada no es correcta",
|
||||
"There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero"
|
||||
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles"
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ module.exports = Self => {
|
|||
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
|
||||
const canCreateAbsenceInPast = await models.ACL.checkAccessAcl(ctx, 'Worker', 'canCreateAbsenceInPast', 'WRITE');
|
||||
const labour = await models.WorkerLabour.findById(args.businessFk, {
|
||||
include: {relation: 'department'}
|
||||
}, myOptions);
|
||||
|
@ -113,6 +114,11 @@ module.exports = Self => {
|
|||
if ((holiday && isFestive) && (workCenter.workcenterFk === holiday.workCenterFk))
|
||||
throw new UserError(`Cannot add holidays on this day`);
|
||||
|
||||
const newDate = new Date(args.dated).getTime();
|
||||
const nowDate = now.getTime();
|
||||
if ((nowDate > newDate) && !canCreateAbsenceInPast)
|
||||
throw new UserError(`Holidays to past days not available`);
|
||||
|
||||
const absence = await models.Calendar.create({
|
||||
businessFk: labour.businessFk,
|
||||
dayOffTypeFk: args.absenceTypeId,
|
||||
|
|
|
@ -162,4 +162,33 @@ describe('Worker createAbsence()', () => {
|
|||
|
||||
expect(error.message).toEqual(`The worker has hours recorded that day`);
|
||||
});
|
||||
|
||||
it(`Should throw an error when adding a "Vacation" absence on a past day`, async() => {
|
||||
const ctx = {
|
||||
req: {accessToken: {userId: 19}},
|
||||
args: {
|
||||
id: 1110,
|
||||
businessFk: 1110,
|
||||
absenceTypeId: 1,
|
||||
dated: '2000-12-27T23:00:00.000Z',
|
||||
}
|
||||
};
|
||||
const workerId = 19;
|
||||
|
||||
const tx = await app.models.Calendar.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
await app.models.Worker.createAbsence(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(`Holidays to past days not available`);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue