unit/#102-base-management #121
3 changed files with 56 additions and 0 deletions
|
@ -18,6 +18,8 @@ import { FileSystemHelper } from "../../../helpers/fileSystemHelper";
|
||||||
import { PdfExport } from "../../../helpers/pdfExport";
|
import { PdfExport } from "../../../helpers/pdfExport";
|
||||||
import { PDFDocument } from "pdf-lib";
|
import { PDFDocument } from "pdf-lib";
|
||||||
import sharp from "sharp";
|
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
|
* @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
|
* @description get inspection by id
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
updateInspectionResults,
|
updateInspectionResults,
|
||||||
getInspectionPrintoutById,
|
getInspectionPrintoutById,
|
||||||
finishInspection,
|
finishInspection,
|
||||||
|
getInspectionPointUpload,
|
||||||
} from "../../../controller/admin/unit/inspectionController";
|
} from "../../../controller/admin/unit/inspectionController";
|
||||||
import { inspectionFileUpload } from "../../../middleware/multer";
|
import { inspectionFileUpload } from "../../../middleware/multer";
|
||||||
|
|
||||||
|
@ -47,6 +48,10 @@ router.get("/:id/printout", async (req: Request, res: Response) => {
|
||||||
await getInspectionPrintoutById(req, res);
|
await getInspectionPrintoutById(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/:id/:pointId/upload", async (req: Request, res: Response) => {
|
||||||
|
await getInspectionPointUpload(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
PermissionHelper.passCheckMiddleware("create", "unit", "inspection"),
|
PermissionHelper.passCheckMiddleware("create", "unit", "inspection"),
|
||||||
|
|
|
@ -21,4 +21,25 @@ export default abstract class InspectionPointResultService {
|
||||||
throw new DatabaseActionException("SELECT", "inspectionPointResult", err);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue