Skip to content

Commit

Permalink
#2717 everything works
Browse files Browse the repository at this point in the history
  • Loading branch information
superhvarn committed Sep 4, 2024
2 parents 918cc47 + 9a9384d commit de5c0e8
Show file tree
Hide file tree
Showing 91 changed files with 2,531 additions and 2,315 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@types/react-dom": "17.0.1"
},
"dependencies": {
"mitt": "^3.0.1",
"react-hook-form-persist": "^3.0.0",
"typescript": "^4.1.5"
},
Expand Down
10 changes: 10 additions & 0 deletions src/backend/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Organization, User as PrismaUser } from '@prisma/client';

declare global {
namespace Express {
export interface Request {
currentUser: PrismaUser;
organization: Organization;
}
}
}
5 changes: 4 additions & 1 deletion src/backend/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import { prodHeaders, requireJwtDev, requireJwtProd } from './src/utils/auth.utils';
import { getUserAndOrganization, prodHeaders, requireJwtDev, requireJwtProd } from './src/utils/auth.utils';
import { errorHandler } from './src/utils/errors.utils';
import userRouter from './src/routes/users.routes';
import projectRouter from './src/routes/projects.routes';
Expand Down Expand Up @@ -49,6 +49,9 @@ app.use(cors(options));
// ensure each request is authorized using JWT
app.use(isProd ? requireJwtProd : requireJwtDev);

// get user and organization
app.use(getUserAndOrganization);

// routes
app.use('/users', userRouter);
app.use('/projects', projectRouter);
Expand Down
18 changes: 6 additions & 12 deletions src/backend/src/controllers/cars.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import { NextFunction, Request, Response } from 'express';
import CarsService from '../services/car.services';
import { getCurrentUser } from '../utils/auth.utils';
import { getOrganizationId } from '../utils/utils';

export default class CarsController {
static async getAllCars(req: Request, res: Response, next: NextFunction) {
try {
const organizationId = getOrganizationId(req.headers);
await getCurrentUser(res);
const cars = await CarsService.getAllCars(organizationId);
const cars = await CarsService.getAllCars(req.organization);

res.status(200).json(cars);
return res.status(200).json(cars);
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async createCar(req: Request, res: Response, next: NextFunction) {
try {
const organizationId = getOrganizationId(req.headers);
const user = await getCurrentUser(res);
const { name } = req.body;
const car = await CarsService.createCar(organizationId, user, name);
const car = await CarsService.createCar(req.organization, req.currentUser, name);

res.status(201).json(car);
return res.status(201).json(car);
} catch (error: unknown) {
next(error);
return next(error);
}
}
}
84 changes: 32 additions & 52 deletions src/backend/src/controllers/change-requests.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
import { Request, Response, NextFunction } from 'express';
import ChangeRequestsService from '../services/change-requests.services';
import { getCurrentUser } from '../utils/auth.utils';
import { User } from '@prisma/client';
import { getOrganizationId } from '../utils/utils';

export default class ChangeRequestsController {
static async getChangeRequestByID(req: Request, res: Response, next: NextFunction) {
try {
const { crId } = req.params;
const organizationId = getOrganizationId(req.headers);

const cr = await ChangeRequestsService.getChangeRequestByID(crId, organizationId);
res.status(200).json(cr);
const cr = await ChangeRequestsService.getChangeRequestByID(crId, req.organization);
return res.status(200).json(cr);
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async getAllChangeRequests(req: Request, res: Response, next: NextFunction) {
try {
const organizationId = getOrganizationId(req.headers);

const changeRequests = await ChangeRequestsService.getAllChangeRequests(organizationId);
res.status(200).json(changeRequests);
const changeRequests = await ChangeRequestsService.getAllChangeRequests(req.organization);
return res.status(200).json(changeRequests);
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async reviewChangeRequest(req: Request, res: Response, next: NextFunction) {
try {
const { crId, reviewNotes, accepted, psId } = req.body;
const organizationId = getOrganizationId(req.headers);
const reviewer = await getCurrentUser(res);
const id = await ChangeRequestsService.reviewChangeRequest(
reviewer,
req.currentUser,
crId,
reviewNotes,
accepted,
organizationId,
req.organization,
psId
);
res.status(200).json({ message: `Change request #${id} successfully reviewed.` });
return res.status(200).json({ message: `Change request #${id} successfully reviewed.` });
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async createActivationChangeRequest(req: Request, res: Response, next: NextFunction) {
try {
const { wbsNum, type, leadId, managerId, startDate, confirmDetails } = req.body;
const submitter = await getCurrentUser(res);
const organizationId = getOrganizationId(req.headers);

const id = await ChangeRequestsService.createActivationChangeRequest(
submitter,
req.currentUser,
wbsNum.carNumber,
wbsNum.projectNumber,
wbsNum.workPackageNumber,
Expand All @@ -63,106 +53,96 @@ export default class ChangeRequestsController {
managerId,
startDate,
confirmDetails,
organizationId
req.organization
);
res.status(200).json({ message: `Successfully created activation change request with id #${id}` });
return res.status(200).json({ message: `Successfully created activation change request with id #${id}` });
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async createStageGateChangeRequest(req: Request, res: Response, next: NextFunction) {
try {
const { wbsNum, type, confirmDone } = req.body;
const submitter = await getCurrentUser(res);
const organizationId = getOrganizationId(req.headers);
const id = await ChangeRequestsService.createStageGateChangeRequest(
submitter,
req.currentUser,
wbsNum.carNumber,
wbsNum.projectNumber,
wbsNum.workPackageNumber,
type,
confirmDone,
organizationId
req.organization
);
res.status(200).json({ message: `Successfully created stage gate request with id #${id}` });
return res.status(200).json({ message: `Successfully created stage gate request with id #${id}` });
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async createStandardChangeRequest(req: Request, res: Response, next: NextFunction) {
try {
const { wbsNum, type, what, why, proposedSolutions, projectProposedChanges, workPackageProposedChanges } = req.body;
const submitter = await getCurrentUser(res);
if (workPackageProposedChanges && workPackageProposedChanges.stage === 'NONE') {
workPackageProposedChanges.stage = null;
}
const organizationId = getOrganizationId(req.headers);

const createdCR = await ChangeRequestsService.createStandardChangeRequest(
submitter,
req.currentUser,
wbsNum.carNumber,
wbsNum.projectNumber,
wbsNum.workPackageNumber,
type,
what,
why,
proposedSolutions,
organizationId,
req.organization,
projectProposedChanges,
workPackageProposedChanges
);
res.status(200).json(createdCR);
return res.status(200).json(createdCR);
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async addProposedSolution(req: Request, res: Response, next: NextFunction) {
try {
const { crId, budgetImpact, description, timelineImpact, scopeImpact } = req.body;
const submitter = await getCurrentUser(res);
const organizationId = getOrganizationId(req.headers);
const id = await ChangeRequestsService.addProposedSolution(
submitter,
req.currentUser,
crId,
budgetImpact,
description,
timelineImpact,
scopeImpact,
organizationId
req.organization
);
res.status(200).json({ message: `Successfully added proposed solution with id #${id}` });
return res.status(200).json({ message: `Successfully added proposed solution with id #${id}` });
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async deleteChangeRequest(req: Request, res: Response, next: NextFunction) {
try {
const { crId } = req.params;
const user: User = await getCurrentUser(res);
const organizationId = getOrganizationId(req.headers);

await ChangeRequestsService.deleteChangeRequest(user, crId, organizationId);
res.status(200).json({ message: `Successfully deleted change request #${crId}` });
await ChangeRequestsService.deleteChangeRequest(req.currentUser, crId, req.organization);
return res.status(200).json({ message: `Successfully deleted change request #${crId}` });
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async requestCRReview(req: Request, res: Response, next: NextFunction) {
try {
const { userIds } = req.body;
const { crId } = req.params;
const submitter: User = await getCurrentUser(res);
const organizationId = getOrganizationId(req.headers);

await ChangeRequestsService.requestCRReview(submitter, userIds, crId, organizationId);
res.status(200).json({ message: `Successfully requested reviewer(s) to change request #${crId}` });
await ChangeRequestsService.requestCRReview(req.currentUser, userIds, crId, req.organization);
return res.status(200).json({ message: `Successfully requested reviewer(s) to change request #${crId}` });
} catch (error: unknown) {
next(error);
return next(error);
}
}
}
42 changes: 17 additions & 25 deletions src/backend/src/controllers/description-bullets.controllers.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,60 @@
import { NextFunction, Request, Response } from 'express';
import DescriptionBulletsService from '../services/description-bullets.services';
import { getCurrentUser } from '../utils/auth.utils';
import { getOrganizationId } from '../utils/utils';

export default class DescriptionBulletsController {
static async checkDescriptionBullet(req: Request, res: Response, next: NextFunction) {
try {
const { descriptionId } = req.body;
const user = await getCurrentUser(res);
const organizationId = getOrganizationId(req.headers);

const updatedDB = await DescriptionBulletsService.checkDescriptionBullet(user, descriptionId, organizationId);
res.status(200).json(updatedDB);
const updatedDB = await DescriptionBulletsService.checkDescriptionBullet(
req.currentUser,
descriptionId,
req.organization
);
return res.status(200).json(updatedDB);
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async getAllDescriptionBulletTypes(req: Request, res: Response, next: NextFunction) {
try {
const organizationId = getOrganizationId(req.headers);

const descriptionBulletTypes = await DescriptionBulletsService.getAllDescriptionBulletTypes(organizationId);
res.status(200).json(descriptionBulletTypes);
const descriptionBulletTypes = await DescriptionBulletsService.getAllDescriptionBulletTypes(req.organization);
return res.status(200).json(descriptionBulletTypes);
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async createDescriptionBulletType(req: Request, res: Response, next: NextFunction) {
try {
const { name, workPackageRequired, projectRequired } = req.body;
const organizationId = getOrganizationId(req.headers);
const user = await getCurrentUser(res);

const newDescriptionBulletType = await DescriptionBulletsService.createDescriptionBulletType(
user,
req.currentUser,
name,
workPackageRequired,
projectRequired,
organizationId
req.organization
);
res.status(201).json(newDescriptionBulletType);
} catch (error: unknown) {
next(error);
return next(error);
}
}

static async editDescriptionBulletType(req: Request, res: Response, next: NextFunction) {
try {
const { name, workPackageRequired, projectRequired } = req.body;
const organizationId = getOrganizationId(req.headers);
const user = await getCurrentUser(res);

const updatedDescriptionBulletType = await DescriptionBulletsService.editDescriptionBulletType(
user,
req.currentUser,
name,
workPackageRequired,
projectRequired,
organizationId
req.organization
);
res.status(200).json(updatedDescriptionBulletType);
return res.status(200).json(updatedDescriptionBulletType);
} catch (error: unknown) {
next(error);
return next(error);
}
}
}
Loading

0 comments on commit de5c0e8

Please sign in to comment.