From 811963e3f2cde48a35155fe82a8f388a4ebfd4d3 Mon Sep 17 00:00:00 2001 From: Pavel Baluev Date: Mon, 24 Jun 2024 14:37:22 +0200 Subject: [PATCH] Skip notification to users about time tracking on public holidays --- .../server/jobs/working-hours-reminder.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/modules/working-hours/server/jobs/working-hours-reminder.ts b/src/modules/working-hours/server/jobs/working-hours-reminder.ts index ac2e13c8..c0d4024e 100644 --- a/src/modules/working-hours/server/jobs/working-hours-reminder.ts +++ b/src/modules/working-hours/server/jobs/working-hours-reminder.ts @@ -40,6 +40,15 @@ export const cronJob: CronJob = { attributes: ['userId'], }).then(fp.map(fp.prop('userId'))) + const publicHolidays = await ctx.models.PublicHoliday.findAll({ + where: { + date: { [Op.in]: ignoreDates }, + }, + }) + const publicHolidaysCalendarIdsToExclude = Array.from( + new Set(publicHolidays.map(fp.prop('calendarId'))) + ) + const recentEntriesUserIds = await ctx.models.WorkingHoursEntry.findAll({ where: { userId: { [Op.notIn]: timeOffUserIds }, @@ -85,13 +94,22 @@ export const cronJob: CronJob = { const userRole = user.roles.find((x) => allowedRoles.includes(x)) const config = configByRole[userRole || ''] if (!config) continue + if ( + config.publicHolidayCalendarId && + publicHolidaysCalendarIdsToExclude.includes( + config.publicHolidayCalendarId + ) + ) { + ctx.log.info(`Skipping user ${user.email} due to public holiday`) + continue + } const response = await ctx.integrations.Matrix.sendMessageToUser( user, message ) if (response.success) { report.succeeded++ - ctx.log.warn(`sent to user ${user.email}`) + ctx.log.info(`Sent Matrix notification to ${user.email}`) } else { ctx.log.error( response.error,