Adding RoleSchema Update/Delete

This commit is contained in:
Laurin
2022-06-09 16:23:54 +02:00
committed by La_Felx
parent 0fea7edb25
commit 418a26b3dd
2 changed files with 29 additions and 3 deletions
+22 -2
View File
@@ -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") { if (req.auth?.permission_level !== "ELEVATED") {
return res.status(403).json(createInsufficientPermissionsError()); return res.status(403).json(createInsufficientPermissionsError());
} }
@@ -177,7 +177,27 @@ export const UpdateRoleSchema = async (req: Request<{ pid: string }>, res: Respo
}); });
} catch (e) { } catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") { 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; throw e;
+7 -1
View File
@@ -2,11 +2,13 @@ import express from "express";
import disciplineRouter from "./discipline.routes"; import disciplineRouter from "./discipline.routes";
import { import {
createRoleSchema, createRoleSchema,
deleteRoleSchema,
getAllRoleSchemas, getAllRoleSchemas,
getAllRoleSchemasWithParam, getAllRoleSchemasWithParam,
getRoleSchema, getRoleSchema,
updateRoleSchema,
} from "../Controllers/role_schema.controller"; } from "../Controllers/role_schema.controller";
import { requireAuthentication } from "../Middleware/auth/auth"; import { requireAuthentication, requireConfiguredAuthentication } from "../Middleware/auth/auth";
const router = express.Router(); const router = express.Router();
@@ -14,6 +16,10 @@ router.get("/", getAllRoleSchemas);
router.get("/:pid", getRoleSchema); 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.get("/:disciplinePid/role-schemas", getAllRoleSchemasWithParam);
disciplineRouter.post("/:disciplinePid/role-schemas", requireAuthentication, createRoleSchema); disciplineRouter.post("/:disciplinePid/role-schemas", requireAuthentication, createRoleSchema);