define routes
This commit is contained in:
parent
9a1e7e74ca
commit
9f2a08ccc9
16 changed files with 1129 additions and 10 deletions
|
@ -0,0 +1,106 @@
|
|||
import { Request, Response } from "express";
|
||||
import InspectionService from "../../../service/unit/inspection/inspectionService";
|
||||
import InspectionFactory from "../../../factory/admin/unit/inspection/inspection";
|
||||
import {
|
||||
CreateInspectionCommand,
|
||||
DeleteInspectionCommand,
|
||||
UpdateInspectionCommand,
|
||||
} from "../../../command/unit/inspection/inspectionCommand";
|
||||
import InspectionCommandHandler from "../../../command/unit/inspection/inspectionCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all inspections for related id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllInspectionsForRelated(req: Request, res: Response): Promise<any> {
|
||||
let relation = req.params.related as "vehicle" | "equipment";
|
||||
let relationId = req.params.relatedId as string;
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
let search = (req.query.search as string) ?? "";
|
||||
let noLimit = req.query.noLimit === "true";
|
||||
let ids = ((req.query.ids ?? "") as string).split(",").filter((i) => i);
|
||||
|
||||
//{ offset, count, search, noLimit, ids }
|
||||
let [inspections, total] = await InspectionService.getAllForRelated({ equipmentId: relationId });
|
||||
|
||||
res.json({
|
||||
inspections: inspections,
|
||||
total: total,
|
||||
offset: offset,
|
||||
count: count,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get inspection by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getInspectionById(req: Request, res: Response): Promise<any> {
|
||||
const inspectionId = req.params.id;
|
||||
let inspection = await InspectionService.getById(inspectionId);
|
||||
|
||||
res.json(InspectionFactory.mapToSingle(inspection));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create inspection
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createInspection(req: Request, res: Response): Promise<any> {
|
||||
const salutationId = parseInt(req.body.salutationId);
|
||||
|
||||
let createInspection: CreateInspectionCommand = {
|
||||
context: "",
|
||||
inspectionPlanId: "",
|
||||
relatedId: "",
|
||||
assigned: "equipment",
|
||||
};
|
||||
let inspectionId = await InspectionCommandHandler.create(createInspection);
|
||||
|
||||
res.status(200).send(inspectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update inspection by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function updateInspectionById(req: Request, res: Response): Promise<any> {
|
||||
const inspectionId = req.params.id;
|
||||
const salutationId = parseInt(req.body.salutationId);
|
||||
|
||||
let updateInspection: UpdateInspectionCommand = {
|
||||
id: inspectionId,
|
||||
context: "",
|
||||
};
|
||||
await InspectionCommandHandler.update(updateInspection);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete inspection by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function deleteInspectionById(req: Request, res: Response): Promise<any> {
|
||||
const inspectionId = req.params.id;
|
||||
|
||||
// TODO finished inspection cannot be deleted
|
||||
|
||||
let deleteInspection: DeleteInspectionCommand = {
|
||||
id: inspectionId,
|
||||
};
|
||||
await InspectionCommandHandler.delete(deleteInspection);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue