From 25891e0bada36df43d809e00024504dc8808ca55 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 11 Nov 2024 10:42:06 +0100 Subject: [PATCH 1/4] feat: refs #6924 notify absences only to department boss --- modules/worker/back/methods/worker/createAbsence.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 0397886cf..c7f968edb 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -87,7 +87,8 @@ module.exports = Self => { `SELECT COUNT(*) halfHolidayCounter FROM vn.calendar c JOIN vn.business b ON b.id = c.businessFk - WHERE c.dayOffTypeFk = 6 + JOIN vn.absenceType at ON at.id = c.dayOffTypeFk + WHERE at.code = 'halfHoliday' AND b.workerFk = ? AND c.dated BETWEEN util.firstDayOfYear(?) AND LAST_DAY(DATE_ADD(?, INTERVAL 12 - MONTH(?) MONTH))`, [id, date, now, now]); @@ -120,10 +121,12 @@ module.exports = Self => { }, myOptions); const department = labour.department(); - if (department && department.notificationEmail) { + if (department) { const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions); const account = await models.VnUser.findById(userId, null, myOptions); const subordinated = await models.VnUser.findById(id, null, myOptions); + const worker = await models.Worker.findById(subordinated.id, null, myOptions); + const boss = await models.VnUser.findById(worker.bossFk, null, myOptions); const url = await Self.app.models.Url.getUrl(); const body = $t('Created absence', { author: account.nickname, @@ -135,7 +138,7 @@ module.exports = Self => { await models.Mail.create({ subject: $t('Absence change notification on the labour calendar'), body: body, - receiver: department.notificationEmail + receiver: boss.email }, myOptions); } From ea4adbea85fb21feea9745cc71234987dca85e15 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 13 Nov 2024 08:45:44 +0100 Subject: [PATCH 2/4] refactor: refs #6924 deleted department check --- .../back/methods/worker/createAbsence.js | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index c7f968edb..036e2bef7 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -120,27 +120,23 @@ module.exports = Self => { dated: args.dated }, myOptions); - const department = labour.department(); - if (department) { - const absenceType = await models.AbsenceType.findById(args.absenceTypeId, null, myOptions); - const account = await models.VnUser.findById(userId, null, myOptions); - const subordinated = await models.VnUser.findById(id, null, myOptions); - const worker = await models.Worker.findById(subordinated.id, null, myOptions); - const boss = await models.VnUser.findById(worker.bossFk, null, myOptions); - const url = await Self.app.models.Url.getUrl(); - const body = $t('Created absence', { - author: account.nickname, - employee: subordinated.nickname, - absenceType: absenceType.name, - dated: formatDate(args.dated), - workerUrl: `${url}worker/${id}/calendar` - }); - await models.Mail.create({ - subject: $t('Absence change notification on the labour calendar'), - body: body, - receiver: boss.email - }, myOptions); - } + const account = await models.VnUser.findById(userId, null, myOptions); + const subordinated = await models.VnUser.findById(id, null, myOptions); + const worker = await models.Worker.findById(subordinated.id, null, myOptions); + const departmentBoss = await models.VnUser.findById(worker.bossFk, null, myOptions); + const url = await Self.app.models.Url.getUrl(); + const body = $t('Created absence', { + author: account.nickname, + employee: subordinated.nickname, + absenceType: absenceType.name, + dated: formatDate(args.dated), + workerUrl: `${url}worker/${id}/calendar` + }); + await models.Mail.create({ + subject: $t('Absence change notification on the labour calendar'), + body: body, + receiver: departmentBoss.email + }, myOptions); if (tx) await tx.commit(); From 7be1bc385f90465b34edbc91763166642a0636b5 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 14 Nov 2024 08:35:28 +0100 Subject: [PATCH 3/4] perf: refs #6924 deleted useless relation --- modules/worker/back/methods/worker/createAbsence.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 036e2bef7..8e6380c3b 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -58,9 +58,7 @@ module.exports = Self => { if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); - const labour = await models.WorkerLabour.findById(args.businessFk, { - include: {relation: 'department'} - }, myOptions); + const labour = await models.WorkerLabour.findById(args.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`); From f145649fc73d979b2429cbd638e6b2c79aafe1c3 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 19 Nov 2024 13:40:31 +0100 Subject: [PATCH 4/4] fix: refs #6924 requested change --- modules/worker/back/methods/worker/createAbsence.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 8e6380c3b..419659083 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -58,7 +58,8 @@ module.exports = Self => { if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss)) throw new UserError(`You don't have enough privileges`); - const labour = await models.WorkerLabour.findById(args.businessFk, myOptions); + 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`);