Skip to content

Commit 9570f46

Browse files
authored
Merge pull request #3624 from Northeastern-Electric-Racing/user-endpoint-speedup
2 parents f89ffb1 + b6c76a6 commit 9570f46

132 files changed

Lines changed: 951 additions & 819 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/backend/custom.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Organization, User as PrismaUser } from '@prisma/client';
1+
import { Organization } from '@prisma/client';
2+
import { User as SharedUser } from 'shared';
23

34
declare global {
45
namespace Express {
56
export interface Request {
6-
currentUser: PrismaUser;
7+
currentUser: SharedUser;
78
organization: Organization;
89
}
910
}

src/backend/src/controllers/tasks.controllers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,15 @@ export default class TasksController {
8989
next(error);
9090
}
9191
}
92+
93+
static async getOverdueTasksByTeamLeadership(req: Request, res: Response, next: NextFunction) {
94+
try {
95+
const { userId } = req.params;
96+
97+
const tasks = await TasksService.getOverdueTasksByTeamLeadership(userId, req.organization);
98+
res.status(200).json(tasks);
99+
} catch (error: unknown) {
100+
next(error);
101+
}
102+
}
92103
}

src/backend/src/controllers/teams.controllers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NextFunction, Request, Response } from 'express';
22
import TeamsService from '../services/teams.services';
33
import { HttpException } from '../utils/errors.utils';
4-
import { WorkPackage } from 'shared';
54

65
export default class TeamsController {
76
static async getAllTeams(req: Request, res: Response, next: NextFunction) {
@@ -260,10 +259,10 @@ export default class TeamsController {
260259
}
261260
}
262261

263-
static async getMyTeamsWorkpackages(req: Request, res: Response, next: NextFunction) {
262+
static async getMyTeamAsHead(req: Request, res: Response, next: NextFunction) {
264263
try {
265-
const workPackages: WorkPackage[] = await TeamsService.getMyTeamsWorkpackages(req.currentUser, req.organization);
266-
res.json(workPackages);
264+
const team = await TeamsService.getMyTeamAsHead(req.currentUser, req.organization);
265+
res.json(team);
267266
} catch (error) {
268267
next(error);
269268
}

src/backend/src/controllers/users.controllers.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ export default class UsersController {
66
static async getAllUsers(_req: Request, res: Response, next: NextFunction) {
77
try {
88
const users = await UsersService.getAllUsers();
9+
res.status(200).json(users);
10+
} catch (error: unknown) {
11+
next(error);
12+
}
13+
}
914

15+
static async getAllOrgUsers(req: Request, res: Response, next: NextFunction) {
16+
try {
17+
const users = await UsersService.getAllOrgUsers(req.organization.organizationId);
1018
res.status(200).json(users);
1119
} catch (error: unknown) {
1220
next(error);
@@ -209,4 +217,16 @@ export default class UsersController {
209217
next(error);
210218
}
211219
}
220+
221+
static async getManyUsersWithScheduleSettings(req: Request, res: Response, next: NextFunction) {
222+
try {
223+
const { userIds } = req.body;
224+
225+
const users = await UsersService.getManyUsersWithScheduleSettings(userIds, req.organization);
226+
227+
res.status(200).json(users);
228+
} catch (error: unknown) {
229+
next(error);
230+
}
231+
}
212232
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NextFunction, Request, Response } from 'express';
2-
import { validateWBS, WbsNumber, WorkPackage } from 'shared';
2+
import { validateWBS, WbsNumber, WorkPackage, WorkPackagePreview, WorkPackageSelection } from 'shared';
33
import WorkPackagesService from '../services/work-packages.services';
44

55
/** Controller for operations involving work packages. */
@@ -134,4 +134,20 @@ export default class WorkPackagesController {
134134
next(error);
135135
}
136136
}
137+
138+
static async getHomePageWorkPackages(req: Request, res: Response, next: NextFunction) {
139+
try {
140+
const { selection } = req.params;
141+
142+
const workPackages: WorkPackagePreview[] = await WorkPackagesService.getHomePageWorkPackages(
143+
req.currentUser,
144+
req.organization,
145+
selection as WorkPackageSelection
146+
);
147+
148+
res.status(200).json(workPackages);
149+
} catch (error: unknown) {
150+
next(error);
151+
}
152+
}
137153
}

src/backend/src/prisma-query-args/auth-user.query-args.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,35 @@
11
import { Prisma } from '@prisma/client';
2-
import { getTeamQueryArgs } from './teams.query-args';
32

43
export type AuthUserQueryArgs = ReturnType<typeof getAuthUserQueryArgs>;
54

65
export const getAuthUserQueryArgs = (organizationId: string) =>
76
Prisma.validator<Prisma.UserDefaultArgs>()({
87
include: {
98
userSettings: true,
9+
organizations: true,
1010
teamsAsHead: {
11-
where: {
12-
organizationId
13-
},
14-
...getTeamQueryArgs(organizationId)
11+
select: {
12+
teamId: true,
13+
financeTeam: true
14+
}
1515
},
16-
organizations: true,
1716
teamsAsLead: {
18-
where: {
19-
organizationId
20-
},
21-
...getTeamQueryArgs(organizationId)
22-
},
23-
teamsAsMember: {
24-
where: {
25-
organizationId
17+
select: {
18+
financeTeam: true,
19+
teamId: true
2620
}
2721
},
28-
favoriteProjects: {
29-
where: {
30-
wbsElement: {
31-
organizationId
32-
}
22+
teamsAsMember: {
23+
select: {
24+
financeTeam: true,
25+
teamId: true
3326
}
3427
},
3528
roles: {
3629
where: {
3730
organizationId
3831
}
3932
},
40-
changeRequestsToReview: {
41-
where: {
42-
wbsElement: {
43-
organizationId
44-
}
45-
}
46-
},
4733
onboardingTeamTypes: {
4834
where: {
4935
organizationId

src/backend/src/prisma-query-args/cars.query-args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const getCarQueryArgs = (organizationId: string) =>
1313
lead: getUserQueryArgs(organizationId),
1414
descriptionBullets: getDescriptionBulletQueryArgs(organizationId),
1515
manager: getUserQueryArgs(organizationId),
16-
links: getLinkQueryArgs(organizationId),
16+
links: getLinkQueryArgs(),
1717
changes: {
1818
where: { changeRequest: { dateDeleted: null } },
1919
include: { implementer: getUserQueryArgs(organizationId) }

src/backend/src/prisma-query-args/link-types.query-args.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Prisma } from '@prisma/client';
2-
import { getLinkTypeQueryArgs } from './link-types.query-args';
3-
import { getUserQueryArgs } from './user.query-args';
42

53
export type LinkQueryArgs = ReturnType<typeof getLinkQueryArgs>;
64

7-
export const getLinkQueryArgs = (organizationId: string) =>
5+
export const getLinkQueryArgs = () =>
86
Prisma.validator<Prisma.LinkDefaultArgs>()({
9-
include: { linkType: getLinkTypeQueryArgs(organizationId), creator: getUserQueryArgs(organizationId) }
7+
include: { linkType: true }
108
});

src/backend/src/prisma-query-args/projects.query-args.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Prisma } from '@prisma/client';
2-
import { getLinkQueryArgs } from './links.query-args';
32
import { getUserQueryArgs } from './user.query-args';
43
import { getDescriptionBulletQueryArgs } from './description-bullets.query-args';
54
import { getTeamPreviewQueryArgs } from './teams.query-args';
65
import { getTaskQueryArgs } from './tasks.query-args';
6+
import { getLinkQueryArgs } from './links.query-args';
77
import { getWorkPackagePreviewQueryArgs, getWorkPackageQueryArgs } from './work-packages.query-args';
88

99
export type ProjectQueryArgs = ReturnType<typeof getProjectQueryArgs>;
@@ -23,7 +23,7 @@ export const getProjectQueryArgs = (organizationId: string) =>
2323
manager: getUserQueryArgs(organizationId),
2424
descriptionBullets: { where: { dateDeleted: null }, ...getDescriptionBulletQueryArgs(organizationId) },
2525
tasks: { where: { dateDeleted: null }, ...getTaskQueryArgs(organizationId) },
26-
links: { where: { dateDeleted: null }, ...getLinkQueryArgs(organizationId) },
26+
links: { where: { dateDeleted: null }, ...getLinkQueryArgs() },
2727
changes: {
2828
where: { changeRequest: { dateDeleted: null } },
2929
include: { implementer: getUserQueryArgs(organizationId), changeRequest: true }
@@ -94,7 +94,7 @@ export const getProjectPreviewQueryArgs = (organizationId: string) =>
9494
status: true
9595
}
9696
},
97-
workPackages: getWorkPackagePreviewQueryArgs(organizationId),
97+
workPackages: getWorkPackagePreviewQueryArgs(),
9898
projectId: true,
9999
budget: true,
100100
abbreviation: true,
@@ -122,11 +122,11 @@ export const getProjectOverviewQueryArgs = (organizationId: string) =>
122122
lead: getUserQueryArgs(organizationId),
123123
manager: getUserQueryArgs(organizationId),
124124
status: true,
125-
links: getLinkQueryArgs(organizationId),
125+
links: getLinkQueryArgs(),
126126
tasks: getTaskQueryArgs(organizationId)
127127
}
128128
},
129-
workPackages: getWorkPackagePreviewQueryArgs(organizationId),
129+
workPackages: getWorkPackagePreviewQueryArgs(),
130130
projectId: true,
131131
budget: true,
132132
abbreviation: true,

0 commit comments

Comments
 (0)