unit/#102-base-management #121

Merged
jkeffects merged 35 commits from unit/#102-base-management into milestone/ff-admin-unit 2025-07-14 13:36:35 +00:00
3 changed files with 56 additions and 0 deletions
Showing only changes of commit 9a1bf6dfde - Show all commits

View file

@ -18,6 +18,8 @@ import { FileSystemHelper } from "../../../helpers/fileSystemHelper";
import { PdfExport } from "../../../helpers/pdfExport";
import { PDFDocument } from "pdf-lib";
import sharp from "sharp";
import InspectionPointService from "../../../service/unit/inspection/inspectionPointService";
import InspectionPointResultService from "../../../service/unit/inspection/inspectionPointResultService";
/**
* @description get all inspections sorted by id not having newer inspection
@ -114,6 +116,34 @@ export async function getInspectionPrintoutById(req: Request, res: Response): Pr
});
}
/**
* @description get inspection by id
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function getInspectionPointUpload(req: Request, res: Response): Promise<any> {
const inspectionId = req.params.id;
const inspectionPointId = req.params.pointId;
let result = await InspectionPointResultService.getForInspectionAndPoint(inspectionId, inspectionPointId);
let filepath = FileSystemHelper.formatPath("inspection", inspectionId, result.value);
if (result.inspectionPoint.others === "pdf") {
res.sendFile(filepath, {
headers: {
"Content-Type": "application/pdf",
},
});
} else {
let image = await sharp(filepath).png().toBuffer();
res.set({
"Content-Type": "image/png",
});
res.send(image);
}
}
/**
* @description get inspection by id
* @param req {Request} Express req object

View file

@ -11,6 +11,7 @@ import {
updateInspectionResults,
getInspectionPrintoutById,
finishInspection,
getInspectionPointUpload,
} from "../../../controller/admin/unit/inspectionController";
import { inspectionFileUpload } from "../../../middleware/multer";
@ -47,6 +48,10 @@ router.get("/:id/printout", async (req: Request, res: Response) => {
await getInspectionPrintoutById(req, res);
});
router.get("/:id/:pointId/upload", async (req: Request, res: Response) => {
await getInspectionPointUpload(req, res);
});
router.post(
"/",
PermissionHelper.passCheckMiddleware("create", "unit", "inspection"),

View file

@ -21,4 +21,25 @@ export default abstract class InspectionPointResultService {
throw new DatabaseActionException("SELECT", "inspectionPointResult", err);
});
}
/**
* @description get inspectionPointResults by inspection and point
* @returns {Promise<Array<inspectionPointResult>>}
*/
static async getForInspectionAndPoint(
inspectionId: string,
inspectionPointId: string
): Promise<inspectionPointResult> {
return await dataSource
.getRepository(inspectionPointResult)
.createQueryBuilder("inspectionPointResult")
.leftJoinAndSelect("inspectionPointResult.inspectionPoint", "inspectionPoint")
.where({ inspectionId, inspectionPointId })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "inspectionPointResult", err);
});
}
}