inspection fetch

This commit is contained in:
Julian Krauser 2025-07-09 12:57:37 +02:00
parent a0a8edf7af
commit 95b6cec66d
6 changed files with 189 additions and 21 deletions

View file

@ -8,6 +8,49 @@ import {
} from "../../../command/unit/inspection/inspectionCommand";
import InspectionCommandHandler from "../../../command/unit/inspection/inspectionCommandHandler";
import BadRequestException from "../../../exceptions/badRequestException";
import ForbiddenRequestException from "../../../exceptions/forbiddenRequestException";
/**
* @description get all inspections sorted by id not having newer inspection
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllInspectionsSortedNotHavingNewer(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25");
let noLimit = req.query.noLimit === "true";
let [inspections, total] = await InspectionService.getAllSortedNotHavingNewer({ offset, count, noLimit });
res.json({
inspections: InspectionFactory.mapToBase(inspections),
total: total,
offset: offset,
count: count,
});
}
/**
* @description get all inspections running
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getAllInspectionsRunning(req: Request, res: Response): Promise<any> {
let offset = parseInt((req.query.offset as string) ?? "0");
let count = parseInt((req.query.count as string) ?? "25");
let noLimit = req.query.noLimit === "true";
let [inspections, total] = await InspectionService.getAllRunning({ offset, count, noLimit });
res.json({
inspections: InspectionFactory.mapToBase(inspections),
total: total,
offset: offset,
count: count,
});
}
/**
* @description get all inspections for related id
@ -111,7 +154,10 @@ export async function updateInspectionById(req: Request, res: Response): Promise
export async function deleteInspectionById(req: Request, res: Response): Promise<any> {
const inspectionId = req.params.id;
// TODO finished inspection cannot be deleted
let deleteInspectionData = await InspectionService.getById(inspectionId);
if (deleteInspectionData.finishedAt != null) {
throw new ForbiddenRequestException("Cannot delete as inspection is already finished");
}
let deleteInspection: DeleteInspectionCommand = {
id: inspectionId,