extend wearable and enable maintenance

This commit is contained in:
Julian Krauser 2025-06-13 11:31:34 +02:00
parent aeb1ccbc42
commit b8b2186c58
20 changed files with 457 additions and 93 deletions

View file

@ -42,6 +42,7 @@ import wearableType from "./unit/wearableType";
import inspection from "./unit/inspection";
import inspectionPlan from "./unit/inspectionPlan";
import damageReport from "./unit/damageReport";
import maintenance from "./unit/maintenance";
var router = express.Router({ mergeParams: true });
@ -189,39 +190,75 @@ router.use(
router.use("/setting", PermissionHelper.passCheckMiddleware("read", "management", "setting"), setting);
/** unit */
router.use("/equipment", PermissionHelper.passCheckMiddleware("read", "unit", "equipment"), equipment);
router.use(
"/equipment",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "equipment" },
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
]),
equipment
);
router.use(
"/equipmenttype",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "equipment_type" },
{ requiredPermission: "read", section: "unit", module: "equipment" },
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
]),
equipmentType
);
router.use("/vehicle", PermissionHelper.passCheckMiddleware("read", "unit", "vehicle"), vehicle);
router.use(
"/vehicle",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "vehicle" },
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
]),
vehicle
);
router.use(
"/vehicletype",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "vehicle_type" },
{ requiredPermission: "read", section: "unit", module: "vehicle" },
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
]),
vehicleType
);
router.use("/wearable", PermissionHelper.passCheckMiddleware("read", "unit", "wearable"), wearable);
router.use(
"/wearable",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "wearable" },
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
]),
wearable
);
router.use(
"/wearabletype",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "wearable_type" },
{ requiredPermission: "read", section: "unit", module: "wearable" },
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
]),
wearableType
);
router.use("/inspection", PermissionHelper.passCheckMiddleware("read", "unit", "inspection"), inspection);
router.use(
"/inspection",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "inspection" },
{ requiredPermission: "read", section: "unit", module: "equipment" },
{ requiredPermission: "read", section: "unit", module: "vehicle" },
{ requiredPermission: "read", section: "unit", module: "wearable" },
]),
inspection
);
router.use(
"/inspectionplan",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "inspection_plan" },
{ requiredPermission: "read", section: "unit", module: "inspection" },
{ requiredPermission: "read", section: "unit", module: "equipment_type" },
{ requiredPermission: "read", section: "unit", module: "vehicle_type" },
{ requiredPermission: "read", section: "unit", module: "wearable_type" },
]),
inspectionPlan
);
@ -229,11 +266,22 @@ router.use(
"/damagereport",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "damage_report" },
{ requiredPermission: "read", section: "unit", module: "maintenance" },
{ requiredPermission: "read", section: "unit", module: "equipment" },
{ requiredPermission: "read", section: "unit", module: "vehicle" },
{ requiredPermission: "read", section: "unit", module: "wearable" },
]),
damageReport
);
router.use(
"/mainenance",
PermissionHelper.passCheckSomeMiddleware([
{ requiredPermission: "read", section: "unit", module: "maintenance" },
{ requiredPermission: "read", section: "unit", module: "equipment" },
{ requiredPermission: "read", section: "unit", module: "vehicle" },
{ requiredPermission: "read", section: "unit", module: "wearable" },
]),
maintenance
);
export default router;

View file

@ -10,15 +10,20 @@ import {
var router = express.Router({ mergeParams: true });
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";
}
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);
});
await getAllInspectionsForRelated(req, res);
}
);
router.get("/:id", async (req: Request, res: Response) => {
await getInspectionById(req, res);

View file

@ -15,15 +15,20 @@ 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";
} else {
req.params.related = "equipment";
}
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 getAllInspectionPlansForRelated(req, res);
});
await getAllInspectionPlansForRelated(req, res);
}
);
router.get("/:id", async (req: Request, res: Response) => {
await getInspectionPlanById(req, res);

View file

@ -0,0 +1,43 @@
import express, { Request, Response } from "express";
import PermissionHelper from "../../../helpers/permissionHelper";
import {
getAllMaintenancesByStatus,
getAllMaintenancesForRelated,
getMaintenanceById,
updateMaintenanceById,
} from "../../../controller/admin/unit/maintenanceController";
var router = express.Router({ mergeParams: true });
router.get("/", async (req: Request, res: Response) => {
await getAllMaintenancesByStatus(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 getAllMaintenancesForRelated(req, res);
}
);
router.get("/:id", async (req: Request, res: Response) => {
await getMaintenanceById(req, res);
});
router.patch(
"/:id",
PermissionHelper.passCheckMiddleware("update", "unit", "inspection"),
async (req: Request, res: Response) => {
await updateMaintenanceById(req, res);
}
);
export default router;