From 80b1b5cf6214e87d351320ba6692122107f8d5c5 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Tue, 17 Sep 2024 13:44:54 +0200 Subject: [PATCH] route permissions --- src/routes/admin/award.ts | 31 +++-- src/routes/admin/communicationType.ts | 31 +++-- src/routes/admin/executivePosition.ts | 31 +++-- src/routes/admin/member.ts | 181 ++++++++++++++++++-------- src/routes/admin/membershipStatus.ts | 31 +++-- src/routes/admin/qualification.ts | 31 +++-- 6 files changed, 237 insertions(+), 99 deletions(-) diff --git a/src/routes/admin/award.ts b/src/routes/admin/award.ts index 2bbe880..f9781df 100644 --- a/src/routes/admin/award.ts +++ b/src/routes/admin/award.ts @@ -6,6 +6,7 @@ import { getAwardById, updateAward, } from "../../controller/admin/awardController"; +import PermissionHelper from "../../helpers/permissionHelper"; var router = express.Router({ mergeParams: true }); @@ -17,16 +18,28 @@ router.get("/:id", async (req: Request, res: Response) => { await getAwardById(req, res); }); -router.post("/", async (req: Request, res: Response) => { - await createAward(req, res); -}); +router.post( + "/", + PermissionHelper.passCheckMiddleware("create", "settings", "award"), + async (req: Request, res: Response) => { + await createAward(req, res); + } +); -router.patch("/:id", async (req: Request, res: Response) => { - await updateAward(req, res); -}); +router.patch( + "/:id", + PermissionHelper.passCheckMiddleware("update", "settings", "award"), + async (req: Request, res: Response) => { + await updateAward(req, res); + } +); -router.delete("/:id", async (req: Request, res: Response) => { - await deleteAward(req, res); -}); +router.delete( + "/:id", + PermissionHelper.passCheckMiddleware("delete", "settings", "award"), + async (req: Request, res: Response) => { + await deleteAward(req, res); + } +); export default router; diff --git a/src/routes/admin/communicationType.ts b/src/routes/admin/communicationType.ts index ecdc4ce..2a797f6 100644 --- a/src/routes/admin/communicationType.ts +++ b/src/routes/admin/communicationType.ts @@ -7,6 +7,7 @@ import { getCommunicationTypeById, updateCommunicationType, } from "../../controller/admin/communicationTypeController"; +import PermissionHelper from "../../helpers/permissionHelper"; var router = express.Router({ mergeParams: true }); @@ -22,16 +23,28 @@ router.get("/:id", async (req: Request, res: Response) => { await getCommunicationTypeById(req, res); }); -router.post("/", async (req: Request, res: Response) => { - await createCommunicationType(req, res); -}); +router.post( + "/", + PermissionHelper.passCheckMiddleware("create", "settings", "communication"), + async (req: Request, res: Response) => { + await createCommunicationType(req, res); + } +); -router.patch("/:id", async (req: Request, res: Response) => { - await updateCommunicationType(req, res); -}); +router.patch( + "/:id", + PermissionHelper.passCheckMiddleware("update", "settings", "communication"), + async (req: Request, res: Response) => { + await updateCommunicationType(req, res); + } +); -router.delete("/:id", async (req: Request, res: Response) => { - await deleteCommunicationType(req, res); -}); +router.delete( + "/:id", + PermissionHelper.passCheckMiddleware("delete", "settings", "communication"), + async (req: Request, res: Response) => { + await deleteCommunicationType(req, res); + } +); export default router; diff --git a/src/routes/admin/executivePosition.ts b/src/routes/admin/executivePosition.ts index e79ce85..2d0c934 100644 --- a/src/routes/admin/executivePosition.ts +++ b/src/routes/admin/executivePosition.ts @@ -6,6 +6,7 @@ import { getExecutivePositionById, updateExecutivePosition, } from "../../controller/admin/executivePositionController"; +import PermissionHelper from "../../helpers/permissionHelper"; var router = express.Router({ mergeParams: true }); @@ -17,16 +18,28 @@ router.get("/:id", async (req: Request, res: Response) => { await getExecutivePositionById(req, res); }); -router.post("/", async (req: Request, res: Response) => { - await createExecutivePosition(req, res); -}); +router.post( + "/", + PermissionHelper.passCheckMiddleware("create", "settings", "executive_position"), + async (req: Request, res: Response) => { + await createExecutivePosition(req, res); + } +); -router.patch("/:id", async (req: Request, res: Response) => { - await updateExecutivePosition(req, res); -}); +router.patch( + "/:id", + PermissionHelper.passCheckMiddleware("update", "settings", "executive_position"), + async (req: Request, res: Response) => { + await updateExecutivePosition(req, res); + } +); -router.delete("/:id", async (req: Request, res: Response) => { - await deleteExecutivePosition(req, res); -}); +router.delete( + "/:id", + PermissionHelper.passCheckMiddleware("delete", "settings", "executive_position"), + async (req: Request, res: Response) => { + await deleteExecutivePosition(req, res); + } +); export default router; diff --git a/src/routes/admin/member.ts b/src/routes/admin/member.ts index 8f745b2..2f8c04e 100644 --- a/src/routes/admin/member.ts +++ b/src/routes/admin/member.ts @@ -26,6 +26,7 @@ import { updateMembershipOfMember, updateQualificationOfMember, } from "../../controller/admin/memberController"; +import PermissionHelper from "../../helpers/permissionHelper"; var router = express.Router({ mergeParams: true }); @@ -57,76 +58,148 @@ router.get("/:memberId/communications", async (req: Request, res: Response) => { await getCommunicationsByMember(req, res); }); -router.post("/", async (req: Request, res: Response) => { - await createMember(req, res); -}); +router.post( + "/", + PermissionHelper.passCheckMiddleware("create", "club", "member"), + async (req: Request, res: Response) => { + await createMember(req, res); + } +); -router.post("/:memberId/membership", async (req: Request, res: Response) => { - await addMembershipToMember(req, res); -}); +router.post( + "/:memberId/membership", + PermissionHelper.passCheckMiddleware("create", "club", "member"), + async (req: Request, res: Response) => { + await addMembershipToMember(req, res); + } +); -router.post("/:memberId/award", async (req: Request, res: Response) => { - await addAwardToMember(req, res); -}); +router.post( + "/:memberId/award", + PermissionHelper.passCheckMiddleware("create", "club", "member"), + async (req: Request, res: Response) => { + await addAwardToMember(req, res); + } +); -router.post("/:memberId/qualification", async (req: Request, res: Response) => { - await addQualificationToMember(req, res); -}); +router.post( + "/:memberId/qualification", + PermissionHelper.passCheckMiddleware("create", "club", "member"), + async (req: Request, res: Response) => { + await addQualificationToMember(req, res); + } +); -router.post("/:memberId/position", async (req: Request, res: Response) => { - await addExecutivePositionToMember(req, res); -}); +router.post( + "/:memberId/position", + PermissionHelper.passCheckMiddleware("create", "club", "member"), + async (req: Request, res: Response) => { + await addExecutivePositionToMember(req, res); + } +); -router.post("/:memberId/communication", async (req: Request, res: Response) => { - await addCommunicationToMember(req, res); -}); +router.post( + "/:memberId/communication", + PermissionHelper.passCheckMiddleware("create", "club", "member"), + async (req: Request, res: Response) => { + await addCommunicationToMember(req, res); + } +); -router.patch("/:id", async (req: Request, res: Response) => { - await updateMemberById(req, res); -}); +router.patch( + "/:id", + PermissionHelper.passCheckMiddleware("update", "club", "member"), + async (req: Request, res: Response) => { + await updateMemberById(req, res); + } +); -router.patch("/:memberId/membership/:recordId", async (req: Request, res: Response) => { - await updateMembershipOfMember(req, res); -}); +router.patch( + "/:memberId/membership/:recordId", + PermissionHelper.passCheckMiddleware("update", "club", "member"), + async (req: Request, res: Response) => { + await updateMembershipOfMember(req, res); + } +); -router.patch("/:memberId/award/:recordId", async (req: Request, res: Response) => { - await updateAwardOfMember(req, res); -}); +router.patch( + "/:memberId/award/:recordId", + PermissionHelper.passCheckMiddleware("update", "club", "member"), + async (req: Request, res: Response) => { + await updateAwardOfMember(req, res); + } +); -router.patch("/:memberId/qualification/:recordId", async (req: Request, res: Response) => { - await updateQualificationOfMember(req, res); -}); +router.patch( + "/:memberId/qualification/:recordId", + PermissionHelper.passCheckMiddleware("update", "club", "member"), + async (req: Request, res: Response) => { + await updateQualificationOfMember(req, res); + } +); -router.patch("/:memberId/position/:recordId", async (req: Request, res: Response) => { - await updateExecutivePositionOfMember(req, res); -}); +router.patch( + "/:memberId/position/:recordId", + PermissionHelper.passCheckMiddleware("update", "club", "member"), + async (req: Request, res: Response) => { + await updateExecutivePositionOfMember(req, res); + } +); -router.patch("/:memberId/communication/:recordId", async (req: Request, res: Response) => { - await updateCommunicationOfMember(req, res); -}); +router.patch( + "/:memberId/communication/:recordId", + PermissionHelper.passCheckMiddleware("update", "club", "member"), + async (req: Request, res: Response) => { + await updateCommunicationOfMember(req, res); + } +); -router.delete("/:id", async (req: Request, res: Response) => { - await deleteMemberById(req, res); -}); +router.delete( + "/:id", + PermissionHelper.passCheckMiddleware("delete", "club", "member"), + async (req: Request, res: Response) => { + await deleteMemberById(req, res); + } +); -router.delete("/:memberId/membership/:recordId", async (req: Request, res: Response) => { - await deleteMembershipOfMember(req, res); -}); +router.delete( + "/:memberId/membership/:recordId", + PermissionHelper.passCheckMiddleware("delete", "club", "member"), + async (req: Request, res: Response) => { + await deleteMembershipOfMember(req, res); + } +); -router.delete("/:memberId/award/:recordId", async (req: Request, res: Response) => { - await deleteAwardOfMember(req, res); -}); +router.delete( + "/:memberId/award/:recordId", + PermissionHelper.passCheckMiddleware("delete", "club", "member"), + async (req: Request, res: Response) => { + await deleteAwardOfMember(req, res); + } +); -router.delete("/:memberId/qualification/:recordId", async (req: Request, res: Response) => { - await deleteQualificationOfMember(req, res); -}); +router.delete( + "/:memberId/qualification/:recordId", + PermissionHelper.passCheckMiddleware("delete", "club", "member"), + async (req: Request, res: Response) => { + await deleteQualificationOfMember(req, res); + } +); -router.delete("/:memberId/position/:recordId", async (req: Request, res: Response) => { - await deleteExecutivePositionOfMember(req, res); -}); +router.delete( + "/:memberId/position/:recordId", + PermissionHelper.passCheckMiddleware("delete", "club", "member"), + async (req: Request, res: Response) => { + await deleteExecutivePositionOfMember(req, res); + } +); -router.delete("/:memberId/communication/:recordId", async (req: Request, res: Response) => { - await deleteCommunicationOfMember(req, res); -}); +router.delete( + "/:memberId/communication/:recordId", + PermissionHelper.passCheckMiddleware("delete", "club", "member"), + async (req: Request, res: Response) => { + await deleteCommunicationOfMember(req, res); + } +); export default router; diff --git a/src/routes/admin/membershipStatus.ts b/src/routes/admin/membershipStatus.ts index 88e1790..665d97b 100644 --- a/src/routes/admin/membershipStatus.ts +++ b/src/routes/admin/membershipStatus.ts @@ -6,6 +6,7 @@ import { getMembershipStatusById, updateMembershipStatus, } from "../../controller/admin/membershipStatusController"; +import PermissionHelper from "../../helpers/permissionHelper"; var router = express.Router({ mergeParams: true }); @@ -17,16 +18,28 @@ router.get("/:id", async (req: Request, res: Response) => { await getMembershipStatusById(req, res); }); -router.post("/", async (req: Request, res: Response) => { - await createMembershipStatus(req, res); -}); +router.post( + "/", + PermissionHelper.passCheckMiddleware("create", "settings", "membership_status"), + async (req: Request, res: Response) => { + await createMembershipStatus(req, res); + } +); -router.patch("/:id", async (req: Request, res: Response) => { - await updateMembershipStatus(req, res); -}); +router.patch( + "/:id", + PermissionHelper.passCheckMiddleware("update", "settings", "membership_status"), + async (req: Request, res: Response) => { + await updateMembershipStatus(req, res); + } +); -router.delete("/:id", async (req: Request, res: Response) => { - await deleteMembershipStatus(req, res); -}); +router.delete( + "/:id", + PermissionHelper.passCheckMiddleware("delete", "settings", "membership_status"), + async (req: Request, res: Response) => { + await deleteMembershipStatus(req, res); + } +); export default router; diff --git a/src/routes/admin/qualification.ts b/src/routes/admin/qualification.ts index bff506c..cab8f22 100644 --- a/src/routes/admin/qualification.ts +++ b/src/routes/admin/qualification.ts @@ -6,6 +6,7 @@ import { getQualificationById, updateQualification, } from "../../controller/admin/qualificationController"; +import PermissionHelper from "../../helpers/permissionHelper"; var router = express.Router({ mergeParams: true }); @@ -17,16 +18,28 @@ router.get("/:id", async (req: Request, res: Response) => { await getQualificationById(req, res); }); -router.post("/", async (req: Request, res: Response) => { - await createQualification(req, res); -}); +router.post( + "/", + PermissionHelper.passCheckMiddleware("create", "settings", "qualification"), + async (req: Request, res: Response) => { + await createQualification(req, res); + } +); -router.patch("/:id", async (req: Request, res: Response) => { - await updateQualification(req, res); -}); +router.patch( + "/:id", + PermissionHelper.passCheckMiddleware("update", "settings", "qualification"), + async (req: Request, res: Response) => { + await updateQualification(req, res); + } +); -router.delete("/:id", async (req: Request, res: Response) => { - await deleteQualification(req, res); -}); +router.delete( + "/:id", + PermissionHelper.passCheckMiddleware("delete", "settings", "qualification"), + async (req: Request, res: Response) => { + await deleteQualification(req, res); + } +); export default router;