fix: hotfix 7323 createAbsence
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
This commit is contained in:
parent
d6a849727e
commit
cf862202ff
|
@ -0,0 +1,2 @@
|
||||||
|
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||||
|
VALUES ('Worker','isHr','WRITE','ALLOW','ROLE','hr');
|
|
@ -245,6 +245,6 @@
|
||||||
"Invalid or expired verification code": "Invalid or expired verification code",
|
"Invalid or expired verification code": "Invalid or expired verification code",
|
||||||
"Payment method is required": "Payment method is required",
|
"Payment method is required": "Payment method is required",
|
||||||
"The raid information is not correct": "The raid information is not correct",
|
"The raid information is not correct": "The raid information is not correct",
|
||||||
"Sales already moved": "Sales already moved"
|
"Sales already moved": "Sales already moved",
|
||||||
|
"Holidays to past days not available": "Holidays to past days not available"
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,5 +388,6 @@
|
||||||
"ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}",
|
"ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}",
|
||||||
"The web user's email already exists": "El correo del usuario web ya existe",
|
"The web user's email already exists": "El correo del usuario web ya existe",
|
||||||
"Sales already moved": "Ya han sido transferidas",
|
"Sales already moved": "Ya han sido transferidas",
|
||||||
"The raid information is not correct": "La información de la redada no es correcta"
|
"The raid information is not correct": "La información de la redada no es correcta",
|
||||||
|
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles"
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ module.exports = Self => {
|
||||||
try {
|
try {
|
||||||
const isSubordinate = await models.Worker.isSubordinate(ctx, id, myOptions);
|
const isSubordinate = await models.Worker.isSubordinate(ctx, id, myOptions);
|
||||||
const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE');
|
const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE');
|
||||||
|
const isHr = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isHr', 'WRITE');
|
||||||
|
|
||||||
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
@ -113,6 +114,11 @@ module.exports = Self => {
|
||||||
if ((holiday && isFestive) && (workCenter.workcenterFk === holiday.workCenterFk))
|
if ((holiday && isFestive) && (workCenter.workcenterFk === holiday.workCenterFk))
|
||||||
throw new UserError(`Cannot add holidays on this day`);
|
throw new UserError(`Cannot add holidays on this day`);
|
||||||
|
|
||||||
|
const newDate = new Date(ctx.args.dated).getTime();
|
||||||
|
const nowDate = now.getTime();
|
||||||
|
if ((nowDate > newDate) && !isHr)
|
||||||
|
throw new UserError(`Holidays to past days not available`);
|
||||||
|
|
||||||
const absence = await models.Calendar.create({
|
const absence = await models.Calendar.create({
|
||||||
businessFk: labour.businessFk,
|
businessFk: labour.businessFk,
|
||||||
dayOffTypeFk: args.absenceTypeId,
|
dayOffTypeFk: args.absenceTypeId,
|
||||||
|
|
|
@ -162,4 +162,33 @@ describe('Worker createAbsence()', () => {
|
||||||
|
|
||||||
expect(error.message).toEqual(`The worker has hours recorded that day`);
|
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