Skip to content

Commit 09a5d7e

Browse files
authored
Merge pull request #2681 from Northeastern-Electric-Racing/revert-2678-Send-Weekly-Deadline-Checks
Revert "Send Weekly Deadline checks"
2 parents 292dd50 + ed68d71 commit 09a5d7e

5 files changed

Lines changed: 21 additions & 43 deletions

File tree

src/backend/src/controllers/notifications.controllers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { NextFunction, Request, Response } from 'express';
22
import NotificationsService from '../services/notifications.services';
33

44
export default class NotificationsController {
5-
static async sendDailySlackNotifications(_req: Request, res: Response, next: NextFunction) {
5+
static async sendTaskDeadlineSlackNotifications(_req: Request, res: Response, next: NextFunction) {
66
try {
7-
await NotificationsService.sendDailySlackNotifications();
7+
await NotificationsService.sendTaskDeadlineSlackNotifications();
88

99
res.status(200).json({ message: 'Successfully sent task deadline notifications!' });
1010
} catch (error: unknown) {

src/backend/src/routes/notifications.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import NotificationsController from '../controllers/notifications.controllers';
33

44
const notificationsRouter = express.Router();
55

6-
notificationsRouter.post('/task-deadlines', NotificationsController.sendDailySlackNotifications);
6+
notificationsRouter.post('/task-deadlines', NotificationsController.sendTaskDeadlineSlackNotifications);
77

88
export default notificationsRouter;

src/backend/src/services/notifications.services.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,23 @@ import {
33
TaskWithAssignees,
44
endOfDayTomorrow,
55
getTeamFromTaskAssignees,
6+
startOfDayTomorrow,
67
usersToSlackPings
78
} from '../utils/notifications.utils';
89
import { sendMessage } from '../integrations/slack';
9-
import WorkPackagesService from './work-packages.services';
10-
import { addWeeksToDate } from 'shared';
11-
import { HttpException } from '../utils/errors.utils';
1210

1311
export default class NotificationsService {
14-
static async sendDailySlackNotifications() {
15-
await NotificationsService.sendTaskDeadlineSlackNotifications();
16-
const date = new Date();
17-
if (date.getDay() === 1) {
18-
const nextWeek = addWeeksToDate(date, 1);
19-
const ADMIN = process.env.ADMIN_USER_ID;
20-
const admin = await prisma.user.findUnique({ where: { userId: ADMIN } });
21-
if (!admin) throw new HttpException(404, 'Admin user not found');
22-
const organizations = await prisma.organization.findMany();
23-
for (const organization of organizations) {
24-
await WorkPackagesService.slackMessageUpcomingDeadlines(admin, nextWeek, organization.organizationId);
25-
}
26-
}
27-
}
28-
2912
/**
30-
* Sends the task deadline slack notifications for all tasks with a deadline of tomorrow or before that are not done
13+
* Sends the task deadline slack notifications for all tasks with a deadline of tomorrow
3114
*/
3215
static async sendTaskDeadlineSlackNotifications() {
16+
const startOfDay = startOfDayTomorrow();
3317
const endOfDay = endOfDayTomorrow();
3418

3519
const tasks = await prisma.task.findMany({
3620
where: {
3721
deadline: {
22+
gte: startOfDay,
3823
lt: endOfDay
3924
},
4025
status: {

src/backend/src/services/work-packages.services.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Prisma, User, WBS_Element, WBS_Element_Status } from '@prisma/client';
22
import {
3-
calculateEndDate,
43
DescriptionBulletPreview,
54
getDay,
65
isAdmin,
@@ -545,10 +544,9 @@ export default class WorkPackagesService {
545544
});
546545

547546
const upcomingWorkPackages = workPackages
548-
.filter((wp) => getDay(calculateEndDate(wp.startDate, wp.duration)) <= getDay(deadline))
549-
.sort(
550-
(a, b) => calculateEndDate(a.startDate, a.duration).getTime() - calculateEndDate(b.startDate, b.duration).getTime()
551-
);
547+
.map(workPackageTransformer)
548+
.filter((wp) => getDay(wp.endDate) <= getDay(deadline))
549+
.sort((a, b) => a.endDate.getTime() - b.endDate.getTime());
552550

553551
// have to do it like this so it goes sequentially and we can sleep between each because of rate limiting
554552
await upcomingWorkPackages.reduce(

src/backend/src/utils/slack.utils.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeRequest, daysBetween, Task, UserPreview, wbsPipe, calculateEndDate } from 'shared';
1+
import { ChangeRequest, daysBetween, Task, UserPreview, wbsPipe, WorkPackage } from 'shared';
22
import { User } from '@prisma/client';
33
import { editMessage, reactToMessage, replyToMessageInThread, sendMessage } from '../integrations/slack';
44
import { getUserFullName, getUserSlackId } from './users.utils';
@@ -8,9 +8,6 @@ import { Change_Request, Design_Review, Team, WBS_Element } from '@prisma/client
88
import { UserWithSettings } from './auth.utils';
99
import { usersToSlackPings, userToSlackPing } from './notifications.utils';
1010
import { addHours, meetingStartTimePipe } from './design-reviews.utils';
11-
import { WorkPackageQueryArgs } from '../prisma-query-args/work-packages.query-args';
12-
import { Prisma } from '@prisma/client';
13-
import { userTransformer } from '../transformers/user.transformer';
1411

1512
// build the "due" string for the upcoming deadlines slack message
1613
const buildDueString = (daysUntilDeadline: number): string => {
@@ -27,27 +24,25 @@ const buildUserString = (lead?: UserPreview, slackId?: string): string => {
2724
return '(no project lead)';
2825
};
2926

30-
export const sendSlackUpcomingDeadlineNotification = async (
31-
workPackage: Prisma.Work_PackageGetPayload<WorkPackageQueryArgs>
32-
): Promise<void> => {
27+
export const sendSlackUpcomingDeadlineNotification = async (workPackage: WorkPackage): Promise<void> => {
3328
if (process.env.NODE_ENV !== 'production') return; // don't send msgs unless in prod
34-
const endDate = calculateEndDate(workPackage.startDate, workPackage.duration);
3529

36-
const { lead } = workPackage.wbsElement;
30+
const { LEAD_CHANNEL_SLACK_ID } = process.env;
31+
if (!LEAD_CHANNEL_SLACK_ID) return;
32+
33+
const { lead } = workPackage;
3734
const slackId = await getUserSlackId(lead?.userId);
38-
const daysUntilDeadline = daysBetween(endDate, new Date());
35+
const daysUntilDeadline = daysBetween(workPackage.endDate, new Date());
3936

40-
const userString = lead ? buildUserString(userTransformer(lead), slackId) : 'No Lead Set';
37+
const userString = buildUserString(lead, slackId);
4138
const dueString = buildDueString(daysUntilDeadline);
4239

43-
const wbsNumber: string = wbsPipe(workPackage.wbsElement);
40+
const wbsNumber: string = wbsPipe(workPackage.wbsNum);
4441
const wbsString = `<https://finishlinebyner.com/projects/${wbsNumber}|${wbsNumber}>`;
4542

46-
const fullMsg = `${userString} ${wbsString}: ${workPackage.project.wbsElement.name} - ${workPackage.wbsElement.name} ${dueString}`;
43+
const fullMsg = `${userString} ${wbsString}: ${workPackage.projectName} - ${workPackage.name} ${dueString}`;
4744

48-
const promises = workPackage.project.teams.map(async (team) => await sendMessage(team.slackId, fullMsg));
49-
50-
await Promise.all(promises);
45+
await sendMessage(LEAD_CHANNEL_SLACK_ID, fullMsg);
5146
};
5247

5348
/**

0 commit comments

Comments
 (0)