provide files for viewing of uploaded files to inspection points
This commit is contained in:
parent
98ce39efc5
commit
9a1bf6dfde
3 changed files with 56 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue