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

@ -7,6 +7,7 @@ import {
UpdateInspectionCommand,
} from "../../../command/unit/inspection/inspectionCommand";
import InspectionCommandHandler from "../../../command/unit/inspection/inspectionCommandHandler";
import BadRequestException from "../../../exceptions/badRequestException";
/**
* @description get all inspections for related id
@ -25,7 +26,7 @@ export async function getAllInspectionsForRelated(req: Request, res: Response):
let [inspections, total] = await InspectionService.getAllForRelated(where, { offset, count, noLimit });
res.json({
inspections: inspections,
inspections: InspectionFactory.mapToBase(inspections),
total: total,
offset: offset,
count: count,
@ -52,13 +53,21 @@ export async function getInspectionById(req: Request, res: Response): Promise<an
* @returns {Promise<*>}
*/
export async function createInspection(req: Request, res: Response): Promise<any> {
const salutationId = parseInt(req.body.salutationId);
const context = req.body.context;
const inspectionPlanId = req.body.inspectionPlanId;
const relatedId = req.body.relatedId;
const assigned = req.body.assigned;
const nextInspection = req.body.nextInspection || null;
if (assigned != "equipment" && assigned != "vehicle")
throw new BadRequestException("set assigned to equipment or vehicle");
let createInspection: CreateInspectionCommand = {
context: "",
inspectionPlanId: "",
relatedId: "",
assigned: "equipment",
context,
nextInspection,
inspectionPlanId,
relatedId,
assigned,
};
let inspectionId = await InspectionCommandHandler.create(createInspection);
@ -73,11 +82,13 @@ export async function createInspection(req: Request, res: Response): Promise<any
*/
export async function updateInspectionById(req: Request, res: Response): Promise<any> {
const inspectionId = req.params.id;
const salutationId = parseInt(req.body.salutationId);
const context = req.body.context;
const nextInspection = req.body.nextInspection || null;
let updateInspection: UpdateInspectionCommand = {
id: inspectionId,
context: "",
context,
nextInspection,
};
await InspectionCommandHandler.update(updateInspection);