Skip to content

Commit 7ff234d

Browse files
committed
getAllUsers improvements
1 parent 4f1b3f1 commit 7ff234d

69 files changed

Lines changed: 333 additions & 335 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/users.controllers.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ import UsersService from '../services/users.services';
33
import { AccessDeniedException } from '../utils/errors.utils';
44
import { Task } from 'shared';
55
export default class UsersController {
6-
static async getAllUsers(_req: Request, res: Response, next: NextFunction) {
6+
static async getAllUsers(req: Request, res: Response, next: NextFunction) {
77
try {
8-
const users = await UsersService.getAllUsers();
8+
const users = await UsersService.getAllUsers(req.organization.organizationId);
9+
10+
res.status(200).json(users);
11+
} catch (error: unknown) {
12+
next(error);
13+
}
14+
}
15+
16+
static async getAllOrganizationUsers(req: Request, res: Response, next: NextFunction) {
17+
try {
18+
const users = await UsersService.getAllUsers(req.organization.organizationId);
919

1020
res.status(200).json(users);
1121
} catch (error: unknown) {
@@ -209,4 +219,16 @@ export default class UsersController {
209219
next(error);
210220
}
211221
}
222+
223+
static async getManyUsersWithScheduleSettings(req: Request, res: Response, next: NextFunction) {
224+
try {
225+
const { userIds } = req.body;
226+
227+
const users = await UsersService.getManyUsersWithScheduleSettings(userIds, req.organization);
228+
229+
res.status(200).json(users);
230+
} catch (error: unknown) {
231+
next(error);
232+
}
233+
}
212234
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ export type UserScheduleSettingsQueryArgs = ReturnType<typeof getUserScheduleSet
99
// DO NOT CALL ANY OTHER QUERY ARGS FROM HERE TO AVOID CIRCULAR DEPENDENCIES
1010
export const getUserQueryArgs = (organizationId: string) =>
1111
Prisma.validator<Prisma.UserDefaultArgs>()({
12-
include: {
13-
roles: {
14-
where: {
15-
organizationId
16-
}
17-
},
18-
organizations: true
12+
select: {
13+
roles: { where: { organizationId } },
14+
userId: true,
15+
firstName: true,
16+
lastName: true,
17+
email: true
1918
}
2019
});
2120

src/backend/src/prisma/seed-data/projects.seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import { Organization, User } from '@prisma/client';
7-
import { DescriptionBulletPreview, LinkCreateArgs, WbsNumber } from 'shared';
6+
import { Organization } from '@prisma/client';
7+
import { DescriptionBulletPreview, LinkCreateArgs, WbsNumber, User } from 'shared';
88
import ProjectsService from '../../services/projects.services';
99

1010
/**

src/backend/src/prisma/seed-data/statistics.seed.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Graph_Display_Type, Graph_Type, Measure, Organization, User } from '@prisma/client';
1+
import { Graph_Display_Type, Graph_Type, Measure, Organization } from '@prisma/client';
22
import StatisticsService from '../../services/statistics.services';
3+
import { User } from 'shared';
34

45
export const seedGraph = async (
56
startDate: Date | null,

src/backend/src/prisma/seed-data/work-packages.seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import { Organization, User } from '@prisma/client';
7-
import { DescriptionBulletPreview, WbsElementStatus, WbsNumber, WorkPackage } from 'shared';
6+
import { Organization } from '@prisma/client';
7+
import { DescriptionBulletPreview, WbsElementStatus, WbsNumber, WorkPackage, User } from 'shared';
88
import { WorkPackageStage } from 'shared';
99
import WorkPackagesService from '../../services/work-packages.services';
1010

src/backend/src/prisma/seed.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import AnnouncementService from '../services/announcement.services';
5050
import OnboardingServices from '../services/onboarding.services';
5151
import { dbSeedAllParts, dbSeedAllPartTags } from './seed-data/parts.seed';
5252
import FinanceServices from '../services/finance.services';
53+
import { getUserQueryArgs } from '../prisma-query-args/user.query-args';
5354

5455
const prisma = new PrismaClient();
5556

@@ -112,7 +113,7 @@ export const CreatePartReviewFAQ = async (
112113
const performSeed: () => Promise<void> = async () => {
113114
const thomasEmrax = await prisma.user.create({
114115
data: dbSeedAllUsers.thomasEmrax,
115-
include: { userSettings: true, userSecureSettings: true }
116+
include: { userSettings: true, userSecureSettings: true, roles: true }
116117
});
117118

118119
const ner = await prisma.organization.create({

src/backend/src/routes/users.routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isRole, nonEmptyString, intMinZero, validateInputs, isDate } from '../u
77
const userRouter = express.Router();
88

99
userRouter.get('/', UsersController.getAllUsers);
10+
userRouter.post('/scheduleSettings', nonEmptyString(body('userIds.*')), UsersController.getManyUsersWithScheduleSettings);
1011
userRouter.get('/:userId', UsersController.getSingleUser);
1112
userRouter.get('/:userId/settings', UsersController.getUserSettings);
1213
userRouter.get('/secure-settings/current-user', UsersController.getCurrentUserSecureSettings);

src/backend/src/services/boms.services.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Material_Status, Material_Type, Organization, User } from '@prisma/client';
1+
import { Material_Status, Material_Type, Organization } from '@prisma/client';
22
import Decimal from 'decimal.js';
33
import {
44
Manufacturer,
@@ -11,7 +11,8 @@ import {
1111
isHead,
1212
MaterialType,
1313
Material,
14-
Unit
14+
Unit,
15+
User
1516
} from 'shared';
1617
import prisma from '../prisma/prisma';
1718
import {

src/backend/src/services/car.services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Organization, User } from '@prisma/client';
2-
import { isAdmin } from 'shared';
1+
import { Organization } from '@prisma/client';
2+
import { isAdmin, User } from 'shared';
33
import { getCarQueryArgs } from '../prisma-query-args/cars.query-args';
44
import prisma from '../prisma/prisma';
55
import { carTransformer } from '../transformers/cars.transformer';

0 commit comments

Comments
 (0)