Skip to content

Commit

Permalink
Merge pull request #34 from paritytech/feat/working-hours-reminder-pu…
Browse files Browse the repository at this point in the history
…blic-holidays

Skip notification to users about time tracking on public holidays
  • Loading branch information
ba1uev authored Jun 24, 2024
2 parents e0da30d + 811963e commit c99b629
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/modules/working-hours/server/jobs/working-hours-reminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c99b629

Please sign in to comment.