change according to connection from frontend

This commit is contained in:
Julian Krauser 2025-06-04 14:30:57 +02:00
parent 2609ecc1bf
commit e3db523a0e
36 changed files with 611 additions and 173 deletions

View file

@ -40,6 +40,7 @@ import wearable from "./unit/wearable";
import wearableType from "./unit/wearableType";
import inspection from "./unit/inspection";
import inspectionPlan from "./unit/inspectionPlan";
import damageReport from "./unit/damageReport";
var router = express.Router({ mergeParams: true });
@ -215,5 +216,15 @@ router.use(
]),
inspectionPlan
);
router.use(
"/damagereport",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "damage_report" },
{ requiredPermission: "read", section: "unit", module: "equipment" },
{ requiredPermission: "read", section: "unit", module: "vehicle" },
{ requiredPermission: "read", section: "unit", module: "wearable" },
]),
damageReport
);
export default router;

View file

@ -0,0 +1,50 @@
import express, { Request, Response } from "express";
import PermissionHelper from "../../../helpers/permissionHelper";
import {
createInspection,
deleteInspectionById,
getAllInspectionsForRelated,
getInspectionById,
updateInspectionById,
} from "../../../controller/admin/unit/inspectionController";
import {
getAllDamageReportsByStatus,
getAllDamageReportsForRelated,
getDamageReportById,
updateDamageReportById,
} from "../../../controller/admin/unit/damageReportController";
var router = express.Router({ mergeParams: true });
router.get("/", async (req: Request, res: Response) => {
await getAllDamageReportsByStatus(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 getAllDamageReportsForRelated(req, res);
}
);
router.get("/:id", async (req: Request, res: Response) => {
await getDamageReportById(req, res);
});
router.patch(
"/:id",
PermissionHelper.passCheckMiddleware("update", "unit", "inspection"),
async (req: Request, res: Response) => {
await updateDamageReportById(req, res);
}
);
export default router;

View file

@ -3,6 +3,7 @@ import PermissionHelper from "../../../helpers/permissionHelper";
import {
createInspectionPlan,
deleteInspectionPlanById,
getAllInspectionPlans,
getAllInspectionPlansForRelated,
getInspectionPlanById,
updateInspectionPlanById,
@ -10,6 +11,10 @@ import {
var router = express.Router({ mergeParams: true });
router.get("/", async (req: Request, res: Response) => {
await getAllInspectionPlans(req, res);
});
router.get(["/vehicle/:relatedId", "/equipment/:relatedId"], async (req: Request, res: Response) => {
if (req.path.startsWith("/vehicle")) {
req.params.related = "vehicle";

View file

@ -5,6 +5,7 @@ import {
deleteVehicleById,
getAllVehicles,
getVehicleById,
getVehiclesByIds,
updateVehicleById,
} from "../../../controller/admin/unit/vehicleController";
@ -18,6 +19,10 @@ router.get("/:id", async (req: Request, res: Response) => {
await getVehicleById(req, res);
});
router.post("/ids", async (req: Request, res: Response) => {
await getVehiclesByIds(req, res);
});
router.post(
"/",
PermissionHelper.passCheckMiddleware("create", "unit", "vehicle"),

View file

@ -5,6 +5,7 @@ import {
deleteWearableById,
getAllWearables,
getWearableById,
getWearablesByIds,
updateWearableById,
} from "../../../controller/admin/unit/wearableController";
@ -18,6 +19,10 @@ router.get("/:id", async (req: Request, res: Response) => {
await getWearableById(req, res);
});
router.post("/ids", async (req: Request, res: Response) => {
await getWearablesByIds(req, res);
});
router.post(
"/",
PermissionHelper.passCheckMiddleware("create", "unit", "wearable"),

View file

@ -2,11 +2,11 @@ import express, { Request, Response } from "express";
import PermissionHelper from "../../../helpers/permissionHelper";
import {
createWearableType,
deleteWearableTypeById,
getAllWearableTypes,
getWearableTypeById,
updateWearableTypeById,
} from "../../../controller/admin/unit/wearableTypeController";
import { deleteWearableById } from "../../../controller/admin/unit/wearableController";
var router = express.Router({ mergeParams: true });
@ -38,7 +38,7 @@ router.delete(
"/:id",
PermissionHelper.passCheckMiddleware("delete", "unit", "wearable_type"),
async (req: Request, res: Response) => {
await deleteWearableById(req, res);
await deleteWearableTypeById(req, res);
}
);