feat(worker_calendar): add restrictions to add absence and to add hours recorded #812

Merged
carlosjr merged 4 commits from 3275-worker_calendar into dev 2021-11-30 13:14:22 +00:00
5 changed files with 18 additions and 7 deletions
Showing only changes of commit 238577ec8f - Show all commits

View File

@ -0,0 +1,3 @@
UPDATE vn.absenceType
SET code='halfPaidLeave'
WHERE id=15 AND name='Permiso retribuido 1/2 día' AND rgb='#5151c0' AND code IS NULL AND permissionRate=NULL AND holidayEntitlementRate=0.50 AND discountRate=0.00;

View File

@ -1878,6 +1878,7 @@ INSERT INTO `postgresql`.`calendar_state` (`calendar_state_id`, `type`, `rgb`, `
(1, 'Holidays', '#FF4444', 'holiday', 0),
(2, 'Leave of absence', '#C71585', 'absence', 0),
(6, 'Half holiday', '#E65F00', 'halfHoliday', 0),
(15, 'Half Paid Leave', '#5151c0', 'halfPaidLeave', 0),
(20, 'Furlough', '#97B92F', 'furlough', 1),
(21, 'Furlough half day', '#778899', 'halfFurlough', 0.5);

View File

@ -59,8 +59,9 @@ module.exports = Self => {
});
if (absence) {
const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk, null, myOptions);
const isNotHalfAbsence = absenceType.id != 6 && absenceType.id != 15 && absenceType.id != 21;
const isNotHalfAbsence = absenceType.code != 'halfHoliday'
vicent marked this conversation as resolved Outdated

try finding types by code instead of id usage.

try finding types by code instead of id usage.
&& absenceType.code != 'halfPaidLeave'
&& absenceType.code != 'halfFurlough';
if (isNotHalfAbsence)
throw new UserError(`The worker has a marked absence that day`);
}

View File

@ -69,9 +69,13 @@ module.exports = Self => {
FROM vn.workerTimeControl
WHERE userFk = ? AND timed BETWEEN DATE(?) AND CONCAT(DATE(?), ' 23:59:59')
LIMIT 1;`;
const [hasHoursRecorded] = await Self.rawSql(query, [args.id, args.dated, args.dated]);
const [hasHoursRecorded] = await Self.rawSql(query, [id, args.dated, args.dated]);
const isNotHalfAbsence = args.absenceTypeId != 6 && args.absenceTypeId != 15 && args.absenceTypeId != 21;
const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions);
const isNotHalfAbsence = absenceType.code != 'halfHoliday'
&& absenceType.code != 'halfPaidLeave'
&& absenceType.code != 'halfFurlough';
if (hasHoursRecorded && isNotHalfAbsence)
throw new UserError(`The worker has hours recorded that day`);
@ -85,10 +89,10 @@ module.exports = Self => {
WHERE c.dayOffTypeFk = 6
AND pe.workerFk = ?
AND c.dated BETWEEN util.firstDayOfYear(CURDATE())
AND LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH))`, [args.id]);
AND LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH))`, [id]);
const hasHalfHoliday = result.halfHolidayCounter > 0;
const isHalfHoliday = args.absenceTypeId == 6;
const isHalfHoliday = absenceType.code === 'halfHoliday';
if (isHalfHoliday && hasHalfHoliday)
throw new UserError(`Cannot add more than one '1/2 day vacation'`);

View File

@ -77,7 +77,7 @@ describe('Worker createAbsence()', () => {
it(`should throw an error when adding a "Half holiday" absence if there's already one`, async() => {
const ctx = {
req: {accessToken: {userId: 19}},
req: {accessToken: {userId: 9}},
args: {
id: 1,
businessFk: 1,
@ -85,6 +85,7 @@ describe('Worker createAbsence()', () => {
dated: new Date()
}
};
const workerId = 1;
const tx = await app.models.Calendar.beginTransaction({});
@ -113,6 +114,7 @@ describe('Worker createAbsence()', () => {
dated: new Date()
}
};
const workerId = 1106;
const tx = await app.models.Calendar.beginTransaction({});