2025-05-29 10:52:05 +02:00
|
|
|
import express, { Request, Response } from "express";
|
|
|
|
import PermissionHelper from "../../../helpers/permissionHelper";
|
2025-05-31 15:12:16 +02:00
|
|
|
import {
|
|
|
|
createInspection,
|
|
|
|
deleteInspectionById,
|
2025-07-09 12:57:37 +02:00
|
|
|
getAllInspectionsSortedNotHavingNewer,
|
2025-05-31 15:12:16 +02:00
|
|
|
getAllInspectionsForRelated,
|
|
|
|
getInspectionById,
|
|
|
|
updateInspectionById,
|
2025-07-09 12:57:37 +02:00
|
|
|
getAllInspectionsRunning,
|
2025-07-11 14:02:36 +02:00
|
|
|
updateInspectionResults,
|
|
|
|
getInspectionPrintoutById,
|
|
|
|
finishInspection,
|
2025-07-12 17:04:29 +02:00
|
|
|
getInspectionPointUpload,
|
2025-05-31 15:12:16 +02:00
|
|
|
} from "../../../controller/admin/unit/inspectionController";
|
2025-07-11 14:02:36 +02:00
|
|
|
import { inspectionFileUpload } from "../../../middleware/multer";
|
2025-05-29 10:52:05 +02:00
|
|
|
|
|
|
|
var router = express.Router({ mergeParams: true });
|
|
|
|
|
2025-07-09 12:57:37 +02:00
|
|
|
router.get("/next", async (req: Request, res: Response) => {
|
|
|
|
await getAllInspectionsSortedNotHavingNewer(req, res);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get("/running", async (req: Request, res: Response) => {
|
|
|
|
await getAllInspectionsRunning(req, res);
|
|
|
|
});
|
|
|
|
|
2025-06-13 11:31:34 +02:00
|
|
|
router.get(
|
|
|
|
["/vehicle/:relatedId", "/equipment/:relatedId", "/wearable/:relatedId"],
|
|
|
|
async (req: Request, res: Response) => {
|
|
|
|
if (req.path.startsWith("/vehicle")) {
|
|
|
|
req.params.related = "vehicle";
|
|
|
|
} else if (req.path.startsWith("/equipment")) {
|
|
|
|
req.params.related = "equipment";
|
|
|
|
} else {
|
|
|
|
req.params.related = "wearable";
|
|
|
|
}
|
|
|
|
|
|
|
|
await getAllInspectionsForRelated(req, res);
|
2025-05-31 15:12:16 +02:00
|
|
|
}
|
2025-06-13 11:31:34 +02:00
|
|
|
);
|
2025-05-31 15:12:16 +02:00
|
|
|
|
|
|
|
router.get("/:id", async (req: Request, res: Response) => {
|
|
|
|
await getInspectionById(req, res);
|
2025-05-29 10:52:05 +02:00
|
|
|
});
|
|
|
|
|
2025-07-11 14:02:36 +02:00
|
|
|
router.get("/:id/printout", async (req: Request, res: Response) => {
|
|
|
|
await getInspectionPrintoutById(req, res);
|
|
|
|
});
|
|
|
|
|
2025-07-12 17:04:29 +02:00
|
|
|
router.get("/:id/:pointId/upload", async (req: Request, res: Response) => {
|
|
|
|
await getInspectionPointUpload(req, res);
|
|
|
|
});
|
|
|
|
|
2025-05-31 15:12:16 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2025-07-11 14:02:36 +02:00
|
|
|
router.patch(
|
|
|
|
"/:id/results",
|
|
|
|
PermissionHelper.passCheckMiddleware("update", "unit", "inspection"),
|
|
|
|
inspectionFileUpload,
|
|
|
|
async (req: Request, res: Response) => {
|
|
|
|
await updateInspectionResults(req, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
router.patch(
|
|
|
|
"/:id/finish",
|
|
|
|
PermissionHelper.passCheckMiddleware("update", "unit", "inspection"),
|
|
|
|
async (req: Request, res: Response) => {
|
|
|
|
await finishInspection(req, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2025-05-31 15:12:16 +02:00
|
|
|
router.delete(
|
|
|
|
"/:id",
|
|
|
|
PermissionHelper.passCheckMiddleware("delete", "unit", "inspection"),
|
|
|
|
async (req: Request, res: Response) => {
|
|
|
|
await deleteInspectionById(req, res);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2025-05-29 10:52:05 +02:00
|
|
|
export default router;
|