-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2613 from Northeastern-Electric-Racing/Feature-Ve…
…rification Feature verification
- Loading branch information
Showing
73 changed files
with
2,011 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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); | ||
|
||
res.status(200).json(cars); | ||
} catch (error: unknown) { | ||
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); | ||
|
||
res.status(201).json(car); | ||
} catch (error: unknown) { | ||
next(error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Prisma } from '@prisma/client'; | ||
import { getAssemblyQueryArgs, getMaterialQueryArgs } from './bom.query-args'; | ||
import { getDescriptionBulletQueryArgs } from './description-bullets.query-args'; | ||
import { getLinkQueryArgs } from './links.query-args'; | ||
import { getUserQueryArgs } from './user.query-args'; | ||
|
||
export type CarQueryArgs = ReturnType<typeof getCarQueryArgs>; | ||
|
||
export const getCarQueryArgs = (organizationId: string) => | ||
Prisma.validator<Prisma.CarDefaultArgs>()({ | ||
include: { | ||
wbsElement: { | ||
include: { | ||
lead: getUserQueryArgs(organizationId), | ||
descriptionBullets: getDescriptionBulletQueryArgs(organizationId), | ||
manager: getUserQueryArgs(organizationId), | ||
links: getLinkQueryArgs(organizationId), | ||
changes: { | ||
where: { changeRequest: { dateDeleted: null } }, | ||
include: { implementer: getUserQueryArgs(organizationId) } | ||
}, | ||
materials: getMaterialQueryArgs(organizationId), | ||
assemblies: getAssemblyQueryArgs(organizationId) | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...40527165314_add_work_package_proposed_solution_to_project_proposed_solution/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- AlterTable | ||
ALTER TABLE "Work_Package_Proposed_Changes" ADD COLUMN "projectProposedChangesId" TEXT; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Work_Package_Proposed_Changes" ADD CONSTRAINT "Work_Package_Proposed_Changes_projectProposedChangesId_fkey" FOREIGN KEY ("projectProposedChangesId") REFERENCES "Project_Proposed_Changes"("projectProposedChangesId") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import express from 'express'; | ||
import CarsController from '../controllers/cars.controllers'; | ||
|
||
const carsRouter = express.Router(); | ||
|
||
carsRouter.get('/', CarsController.getAllCars); | ||
|
||
carsRouter.post('/create', CarsController.createCar); | ||
|
||
export default carsRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { User } from '@prisma/client'; | ||
import { isAdmin } from 'shared'; | ||
import { getCarQueryArgs } from '../prisma-query-args/cars.query-args'; | ||
import prisma from '../prisma/prisma'; | ||
import { carTransformer } from '../transformers/cars.transformer'; | ||
import { AccessDeniedAdminOnlyException, NotFoundException } from '../utils/errors.utils'; | ||
import { userHasPermission } from '../utils/users.utils'; | ||
|
||
export default class CarsService { | ||
static async getAllCars(organizationId: string) { | ||
const cars = await prisma.car.findMany({ | ||
where: { | ||
wbsElement: { | ||
organizationId | ||
} | ||
}, | ||
...getCarQueryArgs(organizationId) | ||
}); | ||
|
||
return cars.map(carTransformer); | ||
} | ||
|
||
static async createCar(organizationId: string, user: User, name: string) { | ||
if (!(await userHasPermission(user.userId, organizationId, isAdmin))) | ||
throw new AccessDeniedAdminOnlyException('create a car'); | ||
|
||
const organization = await prisma.organization.findUnique({ | ||
where: { | ||
organizationId | ||
} | ||
}); | ||
|
||
if (!organization) { | ||
throw new NotFoundException('Organization', organizationId); | ||
} | ||
|
||
const numExistingCars = await prisma.car.count({ | ||
where: { | ||
wbsElement: { | ||
organizationId | ||
} | ||
} | ||
}); | ||
|
||
const car = await prisma.car.create({ | ||
data: { | ||
wbsElement: { | ||
create: { | ||
name, | ||
carNumber: numExistingCars, | ||
projectNumber: 0, | ||
workPackageNumber: 0, | ||
organization: { | ||
connect: { | ||
organizationId | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
...getCarQueryArgs(organizationId) | ||
}); | ||
|
||
return carTransformer(car); | ||
} | ||
} |
Oops, something went wrong.