diff --git a/src/Controllers/role_schema.controller.ts b/src/Controllers/role_schema.controller.ts index 99c5369..f9a9445 100644 --- a/src/Controllers/role_schema.controller.ts +++ b/src/Controllers/role_schema.controller.ts @@ -136,7 +136,7 @@ export const createRoleSchema = async ( } }; -export const UpdateRoleSchema = async (req: Request<{ pid: string }>, res: Response) => { +export const updateRoleSchema = async (req: Request<{ pid: string }>, res: Response) => { if (req.auth?.permission_level !== "ELEVATED") { return res.status(403).json(createInsufficientPermissionsError()); } @@ -177,7 +177,27 @@ export const UpdateRoleSchema = async (req: Request<{ pid: string }>, res: Respo }); } catch (e) { if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { - throw new NotFoundError("discipline", pid); + throw new NotFoundError("role-schema", pid); + } + + throw e; + } +}; + +export const deleteRoleSchema = async (req: Request<{ pid: string }>, res: Response) => { + if (req.auth?.permission_level !== "ELEVATED") { + return res.status(403).json(createInsufficientPermissionsError()); + } + + const { pid } = req.params; + + try { + await prisma.roleSchema.delete({ where: { pid } }); + + return res.status(204).end(); + } catch (e) { + if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") { + throw new NotFoundError("role-schema", pid); } throw e; diff --git a/src/Routes/role_schema.routes.ts b/src/Routes/role_schema.routes.ts index 688dafc..79d4c83 100644 --- a/src/Routes/role_schema.routes.ts +++ b/src/Routes/role_schema.routes.ts @@ -2,11 +2,13 @@ import express from "express"; import disciplineRouter from "./discipline.routes"; import { createRoleSchema, + deleteRoleSchema, getAllRoleSchemas, getAllRoleSchemasWithParam, getRoleSchema, + updateRoleSchema, } from "../Controllers/role_schema.controller"; -import { requireAuthentication } from "../Middleware/auth/auth"; +import { requireAuthentication, requireConfiguredAuthentication } from "../Middleware/auth/auth"; const router = express.Router(); @@ -14,6 +16,10 @@ router.get("/", getAllRoleSchemas); router.get("/:pid", getRoleSchema); +router.patch("/:pid", requireConfiguredAuthentication({ optional: false, type: "admin" }), updateRoleSchema); + +router.delete("/:pid", requireConfiguredAuthentication({ optional: false, type: "admin" }), deleteRoleSchema) + disciplineRouter.get("/:disciplinePid/role-schemas", getAllRoleSchemasWithParam); disciplineRouter.post("/:disciplinePid/role-schemas", requireAuthentication, createRoleSchema);