update or create inspection versioned plan

This commit is contained in:
Julian Krauser 2025-07-09 16:01:44 +02:00
parent 95b6cec66d
commit db3004fa04
13 changed files with 229 additions and 11 deletions

View file

@ -9,6 +9,11 @@ import {
import InspectionPlanCommandHandler from "../../../command/unit/inspection/inspectionPlanCommandHandler";
import BadRequestException from "../../../exceptions/badRequestException";
import TypeTester from "../../../helpers/typeTester";
import InspectionPointService from "../../../service/unit/inspection/inspectionPointService";
import InspectionPointFactory from "../../../factory/admin/unit/inspection/inspectionPoint";
import InspectionService from "../../../service/unit/inspection/inspectionService";
import InspectionVersionedPlanCommandHandler from "../../../command/unit/inspection/inspectionVersionedPlanCommandHandler";
import InspectionPointCommandHandler from "../../../command/unit/inspection/inspectionPointCommandHandler";
/**
* @description get all inspectionPlans
@ -78,6 +83,25 @@ export async function getAllInspectionPlansForRelated(req: Request, res: Respons
});
}
/**
* @description get inspectionPoints by planid
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getInspectionPointsByPlanId(req: Request, res: Response): Promise<any> {
const inspectionPlanId = req.params.id;
let inspectionPlan = await InspectionPlanService.getById(inspectionPlanId);
if (!inspectionPlan.latestVersionedPlan) {
res.json([]);
} else {
let inspectionPoints = await InspectionPointService.getAllForVersionedPlan(inspectionPlan.latestVersionedPlan.id);
res.json(InspectionPointFactory.mapToBase(inspectionPoints));
}
}
/**
* @description get inspectionPlan by id
* @param req {Request} Express req object
@ -148,6 +172,30 @@ export async function updateInspectionPlanById(req: Request, res: Response): Pro
res.sendStatus(204);
}
/**
* @description get inspectionPoints by planid
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function updateInspectionPointsByPlanId(req: Request, res: Response): Promise<any> {
const inspectionPlanId = req.params.id;
const inspectionPoints = req.body;
let inspectionPlan = await InspectionPlanService.getById(inspectionPlanId);
let usedVersionedPlan = inspectionPlan?.latestVersionedPlan?.id
? await InspectionService.usesVersionedInspectionPlan(inspectionPlan.latestVersionedPlan.id)
: true;
if (usedVersionedPlan) {
await InspectionVersionedPlanCommandHandler.create({ inspectionPlanId }, inspectionPoints);
} else {
await InspectionPointCommandHandler.sync(inspectionPlan.latestVersionedPlan.id, inspectionPoints);
}
res.sendStatus(204);
}
/**
* @description delete inspectionPlan by id
* @param req {Request} Express req object