ff-admin-server/src/routes/admin/unit/inspection.ts

96 lines
2.5 KiB
TypeScript

import express, { Request, Response } from "express";
import PermissionHelper from "../../../helpers/permissionHelper";
import {
createInspection,
deleteInspectionById,
getAllInspectionsSortedNotHavingNewer,
getAllInspectionsForRelated,
getInspectionById,
updateInspectionById,
getAllInspectionsRunning,
updateInspectionResults,
getInspectionPrintoutById,
finishInspection,
getInspectionPointUpload,
} from "../../../controller/admin/unit/inspectionController";
import { inspectionFileUpload } from "../../../middleware/multer";
var router = express.Router({ mergeParams: true });
router.get("/next", async (req: Request, res: Response) => {
await getAllInspectionsSortedNotHavingNewer(req, res);
});
router.get("/running", async (req: Request, res: Response) => {
await getAllInspectionsRunning(req, res);
});
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);
}
);
router.get("/:id", async (req: Request, res: Response) => {
await getInspectionById(req, res);
});
router.get("/:id/printout", async (req: Request, res: Response) => {
await getInspectionPrintoutById(req, res);
});
router.get("/:id/:pointId/upload", async (req: Request, res: Response) => {
await getInspectionPointUpload(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.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);
}
);
router.delete(
"/:id",
PermissionHelper.passCheckMiddleware("delete", "unit", "inspection"),
async (req: Request, res: Response) => {
await deleteInspectionById(req, res);
}
);
export default router;