Skip to content

Commit 1db26ac

Browse files
committed
requested changes
1 parent 5ada025 commit 1db26ac

17 files changed

Lines changed: 62 additions & 45 deletions

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export const getTaskQueryArgs = (organizationId: string) =>
1414
}
1515
});
1616

17-
export const getTaskPreviewQueryArgs = () =>
17+
export const getTaskPreviewQueryArgs = (organizationId: string) =>
1818
Prisma.validator<Prisma.TaskDefaultArgs>()({
1919
include: {
2020
wbsElement: true,
21-
createdBy: true,
22-
assignees: true
21+
createdBy: getUserQueryArgs(organizationId),
22+
assignees: getUserQueryArgs(organizationId)
2323
}
2424
});

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,26 @@ export type UserWithSettingsQueryArgs = ReturnType<typeof getUserWithSettingsQue
77
export type UserScheduleSettingsQueryArgs = ReturnType<typeof getUserScheduleSettingsQueryArgs>;
88

99
// DO NOT CALL ANY OTHER QUERY ARGS FROM HERE TO AVOID CIRCULAR DEPENDENCIES
10-
export const getUserQueryArgs = (organizationId: string) =>
10+
export const getUserQueryArgs = (organizationId?: string) =>
1111
Prisma.validator<Prisma.UserDefaultArgs>()({
1212
select: {
13-
roles: { where: { organizationId } },
13+
roles: organizationId ? { where: { organizationId } } : true,
1414
userId: true,
1515
firstName: true,
1616
lastName: true,
1717
email: true
1818
}
1919
});
2020

21+
export const getUserPreviewQueryArgs = () =>
22+
Prisma.validator<Prisma.UserDefaultArgs>()({
23+
select: {
24+
userId: true,
25+
firstName: true,
26+
lastName: true
27+
}
28+
});
29+
2130
export const getUserWithSettingsQueryArgs = (organizationId: string) =>
2231
Prisma.validator<Prisma.UserDefaultArgs>()({
2332
include: {

src/backend/src/prisma-query-args/work-packages.query-args.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Prisma } from '@prisma/client';
2-
import { getUserQueryArgs } from './user.query-args';
2+
import { getUserPreviewQueryArgs, getUserQueryArgs } from './user.query-args';
33
import { getDescriptionBulletQueryArgs } from './description-bullets.query-args';
44
import { getDesignReviewPreviewQueryArgs } from './design-reviews.query-args';
55
import { getLinkQueryArgs } from './links.query-args';
@@ -51,8 +51,8 @@ export const getWorkPackagePreviewQueryArgs = () =>
5151
dateCreated: true,
5252
dateDeleted: true,
5353
name: true,
54-
lead: { select: { userId: true, firstName: true, lastName: true } },
55-
manager: { select: { userId: true, firstName: true, lastName: true } },
54+
lead: getUserPreviewQueryArgs(),
55+
manager: getUserPreviewQueryArgs(),
5656
status: true
5757
}
5858
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
nonEmptyString,
1111
validateInputs
1212
} from '../utils/validation.utils';
13+
import { WorkPackageSelection } from 'shared';
1314
const workPackagesRouter = express.Router();
1415

1516
workPackagesRouter.get('/', WorkPackagesController.getAllWorkPackages);
@@ -65,7 +66,7 @@ workPackagesRouter.post(
6566

6667
workPackagesRouter.get(
6768
'/home-page/:selection',
68-
param('selection').isIn(['allOverdue', 'leading', 'member']),
69+
param('selection').isIn(Object.values(WorkPackageSelection)),
6970
validateInputs,
7071
WorkPackagesController.getHomePageWorkPackages
7172
);

src/backend/src/services/tasks.services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export default class TasksService {
302302
]
303303
}
304304
},
305-
...getTaskPreviewQueryArgs()
305+
...getTaskPreviewQueryArgs(organization.organizationId)
306306
});
307307

308308
return tasks.map(taskCardPreviewTransformer);

src/backend/src/services/users.services.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,10 @@ export default class UsersService {
3737
*/
3838
static async getAllUsers(): Promise<User[]> {
3939
const users = await prisma.user.findMany({
40-
select: {
41-
roles: true,
42-
userId: true,
43-
firstName: true,
44-
lastName: true,
45-
email: true
46-
}
40+
...getUserQueryArgs(),
41+
orderBy: { firstName: 'asc' }
4742
});
4843

49-
users.sort((a, b) => a.firstName.localeCompare(b.firstName));
50-
5144
return users.map(userTransformer);
5245
}
5346

@@ -59,11 +52,10 @@ export default class UsersService {
5952
static async getAllOrgUsers(organizationId: string): Promise<User[]> {
6053
const users = await prisma.user.findMany({
6154
where: { organizations: { some: { organizationId } } },
62-
...getUserQueryArgs(organizationId)
55+
...getUserQueryArgs(organizationId),
56+
orderBy: { firstName: 'asc' }
6357
});
6458

65-
users.sort((a, b) => a.firstName.localeCompare(b.firstName));
66-
6759
return users.map(userTransformer);
6860
}
6961

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
wbsPipe,
1212
WorkPackage,
1313
WorkPackagePreview,
14-
WorkPackageSelection,
1514
WorkPackageStage,
16-
User
15+
User,
16+
WorkPackageSelection
1717
} from 'shared';
1818
import prisma from '../prisma/prisma';
1919
import {
@@ -37,6 +37,7 @@ import {
3737
import { getBlockingWorkPackages, validateBlockedBys } from '../utils/work-packages.utils';
3838
import { getDescriptionBulletQueryArgs } from '../prisma-query-args/description-bullets.query-args';
3939
import { userHasPermission } from '../utils/users.utils';
40+
import { getUserPreviewQueryArgs } from '../prisma-query-args/user.query-args';
4041

4142
/** Service layer containing logic for work package controller functions. */
4243
export default class WorkPackagesService {
@@ -583,9 +584,9 @@ export default class WorkPackagesService {
583584
selection: WorkPackageSelection
584585
): Promise<WorkPackagePreview[]> {
585586
const selectionArgs =
586-
selection === 'allOverdue'
587+
selection === WorkPackageSelection.ALL_OVERDUE
587588
? {}
588-
: selection === 'leading'
589+
: selection === WorkPackageSelection.LEADING
589590
? {
590591
workPackage: {
591592
project: {
@@ -630,8 +631,8 @@ export default class WorkPackagesService {
630631
workPackageNumber: true,
631632
dateDeleted: true,
632633
wbsElementId: true,
633-
lead: { select: { firstName: true, lastName: true, userId: true } },
634-
manager: { select: { firstName: true, lastName: true, userId: true } }
634+
lead: getUserPreviewQueryArgs(),
635+
manager: getUserPreviewQueryArgs()
635636
}
636637
},
637638
blockedBy: true,
@@ -642,7 +643,7 @@ export default class WorkPackagesService {
642643
}
643644
});
644645

645-
if (selection === 'allOverdue') {
646+
if (selection === WorkPackageSelection.ALL_OVERDUE) {
646647
workPackages = workPackages.filter((wp) => {
647648
const endDate = new Date(wp.startDate);
648649
endDate.setDate(endDate.getDate() + wp.duration * 7); // Add weeks as days

src/backend/src/transformers/description-bullets.transformer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ const descriptionBulletTransformer = (
1212
type: descBullet.descriptionBulletType.name,
1313
dateDeleted: descBullet.dateDeleted ?? undefined,
1414
userChecked: descBullet.userChecked
15-
? { firstName: descBullet.userChecked.firstName, lastName: descBullet.userChecked.lastName }
15+
? {
16+
userId: descBullet.userChecked.userId,
17+
firstName: descBullet.userChecked.firstName,
18+
lastName: descBullet.userChecked.lastName
19+
}
1620
: undefined,
1721
dateChecked: descBullet.dateTimeChecked ?? undefined
1822
};

src/frontend/src/components/CheckList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Typography from '@mui/material/Typography';
1010
import { useReducer, useState } from 'react';
1111
import { useCheckDescriptionBullet } from '../hooks/description-bullets.hooks';
1212
import { Tooltip } from '@mui/material';
13-
import { User } from 'shared';
13+
import { User, UserPreview } from 'shared';
1414
import NERModal from './NERModal';
1515
import { fullNamePipe } from '../utils/pipes';
1616
import { useToast } from '../hooks/toasts.hooks';
@@ -20,7 +20,7 @@ export type CheckListItem = {
2020
id: string;
2121
detail: string;
2222
resolved: boolean;
23-
user?: Pick<User, 'firstName' | 'lastName'>;
23+
user?: UserPreview;
2424
dateChecked?: Date;
2525
};
2626

src/frontend/src/hooks/users.hooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
getManyUserTasks,
2323
getCurrentUser,
2424
logUserOut,
25-
getManyUsersWithScheduleSettings
25+
getManyUsersWithScheduleSettings,
26+
getAllOrgUsers
2627
} from '../apis/users.api';
2728
import {
2829
User,
@@ -55,7 +56,7 @@ export const useCurrentUser = (): AuthenticatedUser => {
5556
*/
5657
export const useAllUsers = () => {
5758
return useQuery<UserWithRole[], Error>(['users'], async () => {
58-
const { data } = await getAllUsers();
59+
const { data } = await getAllOrgUsers();
5960
return data;
6061
});
6162
};

0 commit comments

Comments
 (0)