Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2024-12-09 14:31:37 +01:00
commit 94bc1241e5
6 changed files with 48 additions and 10 deletions

View File

@ -0,0 +1,2 @@
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Worker','canCreateAbsenceInPast','WRITE','ALLOW','ROLE','hr');

View File

@ -247,5 +247,5 @@
"The raid information is not correct": "The raid information is not correct",
"Payment method is required": "Payment method is required",
"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"
}

View File

@ -391,6 +391,7 @@
"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",
"An item type with the same code already exists": "Un tipo con el mismo código ya existe"
"An item type with the same code already exists": "Un tipo con el mismo código ya existe",
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles"
}

View File

@ -86,7 +86,7 @@ module.exports = Self => {
return /^\d+$/.test(value)
? {'t.id': value}
: {'t.ref': {like: `%${value}%`}};
case 'ref':
case 'reference':
return {'t.ref': {like: `%${value}%`}};
case 'shippedFrom':
return {'t.shipped': {gte: value}};

View File

@ -58,17 +58,24 @@ 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 now = Date.vnNew();
const newDate = new Date(args.dated).getTime();
if ((now.getTime() > newDate) && !canCreateAbsenceInPast)
throw new UserError(`Holidays to past days not available`);
const labour = await models.WorkerLabour.findById(args.businessFk,
{fields: ['started', 'ended', 'businessFk']}, myOptions);
if (args.dated < labour.started || (labour.ended != null && args.dated > labour.ended))
throw new UserError(`The contract was not active during the selected date`);
query = `SELECT *
const [hasHoursRecorded] = await Self.rawSql(`SELECT *
FROM vn.workerTimeControl
WHERE userFk = ? AND timed BETWEEN DATE(?) AND CONCAT(DATE(?), ' 23:59:59')
LIMIT 1;`;
const [hasHoursRecorded] = await Self.rawSql(query, [id, args.dated, args.dated]);
LIMIT 1;`, [id, args.dated, args.dated]);
const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions);
@ -80,7 +87,6 @@ module.exports = Self => {
throw new UserError(`The worker has hours recorded that day`);
const date = Date.vnNew();
const now = Date.vnNew();
date.setHours(0, 0, 0, 0);
const [result] = await Self.rawSql(
`SELECT COUNT(*) halfHolidayCounter

View File

@ -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`);
});
});