2025-05-28 17:06:56 +02:00
|
|
|
import { dataSource } from "../../../data-source";
|
|
|
|
import { inspection } from "../../../entity/unit/inspection/inspection";
|
|
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
|
|
|
|
|
|
export default abstract class InspectionService {
|
|
|
|
/**
|
2025-05-28 17:32:07 +02:00
|
|
|
* @description get all inspections for related
|
2025-05-28 17:06:56 +02:00
|
|
|
* @returns {Promise<Array<inspection>>}
|
|
|
|
*/
|
2025-05-28 17:32:07 +02:00
|
|
|
static async getAllForRelated(where: { equipmentId: string } | { vehicleId: string }): Promise<Array<inspection>> {
|
2025-05-28 17:06:56 +02:00
|
|
|
return await dataSource
|
|
|
|
.getRepository(inspection)
|
|
|
|
.createQueryBuilder("inspection")
|
2025-05-28 17:32:07 +02:00
|
|
|
.leftJoinAndSelect("inspection.inspectionPlan", "inspectionPlan")
|
|
|
|
.leftJoinAndSelect("inspection.inspectionVersionedPlan", "inspectionVersionedPlan")
|
|
|
|
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
|
|
|
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
|
|
|
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
2025-05-28 18:30:00 +02:00
|
|
|
.leftJoinAndSelect("inspection.equipment", "equipment")
|
|
|
|
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
2025-05-28 17:32:07 +02:00
|
|
|
.where(where)
|
|
|
|
.orderBy("createdAt", "DESC")
|
2025-05-28 17:06:56 +02:00
|
|
|
.getMany()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
throw new DatabaseActionException("SELECT", "inspection", err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get inspection by id
|
|
|
|
* @returns {Promise<inspection>}
|
|
|
|
*/
|
|
|
|
static async getById(id: string): Promise<inspection> {
|
|
|
|
return await dataSource
|
|
|
|
.getRepository(inspection)
|
|
|
|
.createQueryBuilder("inspection")
|
2025-05-28 17:32:07 +02:00
|
|
|
.leftJoinAndSelect("inspection.inspectionPlan", "inspectionPlan")
|
|
|
|
.leftJoinAndSelect("inspection.inspectionVersionedPlan", "inspectionVersionedPlan")
|
|
|
|
.leftJoinAndSelect("inspectionVersionedPlan.inspectionPoints", "inspectionPoints")
|
|
|
|
.leftJoinAndSelect("inspection.pointResults", "pointResults")
|
|
|
|
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
|
2025-05-28 18:30:00 +02:00
|
|
|
.leftJoinAndSelect("inspection.equipment", "equipment")
|
|
|
|
.leftJoinAndSelect("inspection.vehicle", "vehicle")
|
2025-05-28 17:06:56 +02:00
|
|
|
.where({ id })
|
|
|
|
.getOneOrFail()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
throw new DatabaseActionException("SELECT", "inspection", err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|