Skip to content

Commit 7d97b47

Browse files
committed
Merge branch 'develop' into Send-Weekly-Deadline-Checks
2 parents 56c7064 + 5731362 commit 7d97b47

27 files changed

Lines changed: 122 additions & 160 deletions

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/controllers/projects.controllers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import { getOrganizationId } from '../utils/utils';
99
export default class ProjectsController {
1010
static async getAllProjects(req: Request, res: Response, next: NextFunction) {
1111
try {
12+
const includeDeleted = req.params.deleted === 'true';
1213
const organizationId = getOrganizationId(req.headers);
13-
const projects: Project[] = await ProjectsService.getAllProjects(organizationId);
14+
const projects: Project[] = await ProjectsService.getAllProjects(organizationId, includeDeleted);
1415
res.status(200).json(projects);
1516
} catch (error: unknown) {
1617
next(error);

src/backend/src/prisma/seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,12 +1947,12 @@ const performSeed: () => Promise<void> = async () => {
19471947
{
19481948
linkId: '1',
19491949
linkTypeName: 'Confluence',
1950-
url: 'https://google.com'
1950+
url: 'https://confluence.com'
19511951
},
19521952
{
19531953
linkId: '2',
19541954
linkTypeName: 'Bill of Materials',
1955-
url: 'https://apple.com'
1955+
url: 'https://docs.google.com'
19561956
}
19571957
]);
19581958
};

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/routes/projects.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ProjectsController from '../controllers/projects.controllers';
1212

1313
const projectRouter = express.Router();
1414

15-
projectRouter.get('/', ProjectsController.getAllProjects);
15+
projectRouter.get('/all/:deleted', ProjectsController.getAllProjects);
1616

1717
/* Link Types */
1818
projectRouter.get('/link-types', ProjectsController.getAllLinkTypes);

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,25 @@ 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, daysBetween } from 'shared';
11-
import { HttpException } from '../utils/errors.utils';
10+
import { daysBetween } from 'shared';
1211
import { buildDueString } from '../utils/slack.utils';
1312

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

3621
const tasks = await prisma.task.findMany({
3722
where: {
3823
deadline: {
24+
gte: startOfDay,
3925
lt: endOfDay
4026
},
4127
status: {

src/backend/src/services/projects.services.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ export default class ProjectsService {
3636
/**
3737
* Get all the non deleted projects in the database for the given organization.
3838
* @param organizationId the id of the organization the user is currently in
39+
* @param includeDeleted whether or not to include deleted projects
3940
* @returns all the projects
4041
*/
41-
static async getAllProjects(organizationId: string): Promise<Project[]> {
42-
const projects = await prisma.project.findMany({
43-
where: { wbsElement: { dateDeleted: null, organizationId } },
44-
...getProjectQueryArgs(organizationId)
45-
});
42+
static async getAllProjects(organizationId: string, includeDeleted: boolean): Promise<Project[]> {
43+
const projects = includeDeleted
44+
? await prisma.project.findMany({
45+
where: { wbsElement: { organizationId } },
46+
...getProjectQueryArgs(organizationId)
47+
})
48+
: await prisma.project.findMany({
49+
where: { wbsElement: { dateDeleted: null, organizationId } },
50+
...getProjectQueryArgs(organizationId)
51+
});
4652
return projects.map(projectTransformer);
4753
}
4854

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/transformers/cars.transformer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const carTransformer = (car: Prisma.CarGetPayload<CarQueryArgs>): Car =>
2121
descriptionBullets: car.wbsElement.descriptionBullets.map(descBulletConverter),
2222
materials: car.wbsElement.materials.map(materialTransformer),
2323
assemblies: car.wbsElement.assemblies.map(assemblyTransformer),
24-
changes: []
24+
changes: [],
25+
deleted: car.wbsElement.dateDeleted !== null
2526
};
2627
};

src/backend/src/transformers/projects.transformer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const projectTransformer = (project: Prisma.ProjectGetPayload<ProjectQueryArgs>)
4141
detail: change.detail,
4242
dateImplemented: change.dateImplemented
4343
})),
44+
deleted: wbsElement.dateDeleted !== null,
4445
favoritedBy: project.favoritedBy.map(userTransformer),
4546
teams: project.teams.map(teamTransformer),
4647
summary: project.summary,
@@ -85,7 +86,8 @@ const projectTransformer = (project: Prisma.ProjectGetPayload<ProjectQueryArgs>)
8586
stage: (workPackage.stage || undefined) as WorkPackageStage,
8687
materials: workPackage.wbsElement?.materials.map(materialTransformer),
8788
assemblies: workPackage.wbsElement?.assemblies.map(assemblyTransformer),
88-
blocking: workPackage.wbsElement.blocking.map((blocking) => wbsNumOf(blocking.wbsElement))
89+
blocking: workPackage.wbsElement.blocking.map((blocking) => wbsNumOf(blocking.wbsElement)),
90+
deleted: workPackage.wbsElement.dateDeleted !== null
8991
};
9092
})
9193
};

0 commit comments

Comments
 (0)