next and running inspections
This commit is contained in:
parent
8747baaf2e
commit
705297ba50
6 changed files with 142 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
import { IsNull } from "typeorm";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
import { dataSource } from "../../../data-source";
|
||||
import { inspection } from "../../../entity/unit/inspection/inspection";
|
||||
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
||||
|
@ -129,6 +129,36 @@ export default abstract class InspectionService {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description uses versionedPlan
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
static async existsUnfinishedInspectionToPlan(
|
||||
inspectionPlanId: string,
|
||||
relation: "vehicle" | "equipment" | "wearable",
|
||||
relationId: string
|
||||
): Promise<boolean> {
|
||||
let where: { equipmentId: string } | { vehicleId: string } | { wearableId: string };
|
||||
if (relation == "equipment") {
|
||||
where = { equipmentId: relationId };
|
||||
} else if (relation == "vehicle") {
|
||||
where = { vehicleId: relationId };
|
||||
} else {
|
||||
where = { wearableId: relationId };
|
||||
}
|
||||
return await dataSource
|
||||
.getRepository(inspection)
|
||||
.createQueryBuilder("inspection")
|
||||
.where({ inspectionPlanId, finishedAt: IsNull(), ...where })
|
||||
.getExists()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "used inspection", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description uses versionedPlan
|
||||
* @returns {Promise<boolean>}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue