11import prisma from '../prisma/prisma' ;
2- import { TaskWithAssignees , getTeamFromTaskAssignees , usersToSlackPings } from '../utils/deadline-notifications.utils' ;
2+ import {
3+ TaskWithAssignees ,
4+ endOfDayTomorrow ,
5+ getTeamFromTaskAssignees ,
6+ startOfDayTomorrow ,
7+ usersToSlackPings
8+ } from '../utils/notifications.utils' ;
39import { sendMessage } from '../integrations/slack' ;
410
5- export default class DeadlineNotificationsService {
11+ export default class NotificationsService {
612 /**
7- * Sends the task deadline slack notifications for all tasks with a deadline of the given date
8- * @param deadline the beginning of the deadline date (at 12am)
13+ * Sends the task deadline slack notifications for all tasks with a deadline of tomorrow
914 */
10- static async sendTaskDeadlineSlackNotifications ( deadline : Date ) {
11- const startOfDay = deadline ;
12- const endOfDay = new Date ( startOfDay ) ;
13- endOfDay . setDate ( startOfDay . getDate ( ) + 1 ) ;
15+ static async sendTaskDeadlineSlackNotifications ( ) {
16+ const startOfDay = startOfDayTomorrow ( ) ;
17+ const endOfDay = endOfDayTomorrow ( ) ;
1418
1519 const tasks = await prisma . task . findMany ( {
1620 where : {
@@ -43,7 +47,7 @@ export default class DeadlineNotificationsService {
4347
4448 // group tasks due by team in a map
4549 tasks . forEach ( ( task ) => {
46- const teamSlackId = getTeamFromTaskAssignees ( task . assignees ) ;
50+ const teamSlackId = getTeamFromTaskAssignees ( task . assignees ) . slackId ;
4751
4852 const currentTasks = teamTaskMap . get ( teamSlackId ) ;
4953 if ( currentTasks ) {
@@ -57,6 +61,8 @@ export default class DeadlineNotificationsService {
5761 // send the notifications to each team for their respective tasks
5862 teamTaskMap . forEach ( ( tasks , slackId ) => {
5963 const messageBlock = tasks
64+ // ensures that the task has assignees to send a reminder for
65+ . filter ( ( task ) => task . assignees )
6066 . map (
6167 ( task ) =>
6268 `${ usersToSlackPings ( task . assignees ?? [ ] ) } Reminder: ${ task . title } due tomorrow in project ${
0 commit comments