define routes

This commit is contained in:
Julian Krauser 2025-05-31 15:12:16 +02:00
parent 9a1e7e74ca
commit 9f2a08ccc9
16 changed files with 1129 additions and 10 deletions

View file

@ -1,10 +1,51 @@
import express, { Request, Response } from "express";
import PermissionHelper from "../../../helpers/permissionHelper";
import {
createInspection,
deleteInspectionById,
getAllInspectionsForRelated,
getInspectionById,
updateInspectionById,
} from "../../../controller/admin/unit/inspectionController";
var router = express.Router({ mergeParams: true });
router.get("/", async (req: Request, res: Response) => {
res.send("TODO");
router.get(["/vehicle/:relatedId", "/equipment/:relatedId"], async (req: Request, res: Response) => {
if (req.path.startsWith("/vehicle")) {
req.params.related = "vehicle";
} else {
req.params.related = "equipment";
}
await getAllInspectionsForRelated(req, res);
});
router.get("/:id", async (req: Request, res: Response) => {
await getInspectionById(req, res);
});
router.post(
"/",
PermissionHelper.passCheckMiddleware("create", "unit", "inspection"),
async (req: Request, res: Response) => {
await createInspection(req, res);
}
);
router.patch(
"/:id",
PermissionHelper.passCheckMiddleware("update", "unit", "inspection"),
async (req: Request, res: Response) => {
await updateInspectionById(req, res);
}
);
router.delete(
"/:id",
PermissionHelper.passCheckMiddleware("delete", "unit", "inspection"),
async (req: Request, res: Response) => {
await deleteInspectionById(req, res);
}
);
export default router;