extend wearable and enable maintenance

This commit is contained in:
Julian Krauser 2025-06-13 11:31:34 +02:00
parent aeb1ccbc42
commit b8b2186c58
20 changed files with 457 additions and 93 deletions

View file

@ -16,7 +16,8 @@ export default abstract class InspectionPlanService {
)
.leftJoinAndSelect("latestVersionedPlan.inspectionPoints", "inspectionPoints")
.leftJoinAndSelect("inspectionPlan.equipmentType", "equipmentType")
.leftJoinAndSelect("inspectionPlan.vehicleType", "vehicleType");
.leftJoinAndSelect("inspectionPlan.vehicleType", "vehicleType")
.leftJoinAndSelect("inspectionPlan.wearableType", "wearableType");
/**
* @description get all inspectionPlans for related
@ -67,7 +68,7 @@ export default abstract class InspectionPlanService {
* @returns {Promise<[Array<inspectionPlan>, number]>}
*/
static async getAllForRelated(
where: { equipmentTypeId: string } | { vehicleTypeId: string },
where: { equipmentTypeId: string } | { vehicleTypeId: string } | { wearableTypeId: string },
{
offset = 0,
count = 25,

View file

@ -13,14 +13,15 @@ export default abstract class InspectionService {
.leftJoinAndSelect("inspection.pointResults", "pointResults")
.leftJoinAndSelect("pointResults.inspectionPoint", "inspectionPoint")
.leftJoinAndSelect("inspection.equipment", "equipment")
.leftJoinAndSelect("inspection.vehicle", "vehicle");
.leftJoinAndSelect("inspection.vehicle", "vehicle")
.leftJoinAndSelect("inspection.wearable", "wearable");
/**
* @description get all inspections for related
* @returns {Promise<Array<inspection>>}
*/
static async getAllForRelated(
where: { equipmentId: string } | { vehicleId: string },
where: { equipmentId: string } | { vehicleId: string } | { wearableId: string },
{
offset = 0,
count = 25,

View file

@ -3,20 +3,72 @@ import { maintenance } from "../../entity/unit/maintenance";
import DatabaseActionException from "../../exceptions/databaseActionException";
export default abstract class MaintenanceService {
/**
* @description get all maintenances
* @returns {Promise<Array<maintenance>>}
*/
static async getAll(): Promise<Array<maintenance>> {
return await dataSource
private static query = () =>
dataSource
.getRepository(maintenance)
.createQueryBuilder("maintenance")
.leftJoinAndSelect("maintenance.equipment", "equipment")
.leftJoinAndSelect("maintenance.vehicle", "vehicle")
.leftJoinAndSelect("maintenance.wearable", "wearable")
.leftJoinAndSelect("maintenance.reports", "reports")
.orderBy("type", "ASC")
.getMany()
.leftJoinAndSelect("maintenance.reports", "reports");
/**
* @description get all maintenances
* @returns {Promise<[Array<maintenance>, number]>}
*/
static async getAll(
done = false,
{
offset = 0,
count = 25,
noLimit = false,
}: {
offset?: number;
count?: number;
noLimit?: boolean;
}
): Promise<[Array<maintenance>, number]> {
let query = this.query().where({ done });
if (!noLimit) {
query = query.offset(offset).limit(count);
}
return await query
.orderBy("maintenance.type", "ASC")
.getManyAndCount()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "maintenance", err);
});
}
/**
* @description get all maintenances By related
* @returns {Promise<[Array<maintenance>, number]>}
*/
static async getAllForRelated(
where: { equipmentId: string } | { vehicleId: string } | { wearableId: string },
{
offset = 0,
count = 25,
noLimit = false,
}: {
offset?: number;
count?: number;
noLimit?: boolean;
}
): Promise<[Array<maintenance>, number]> {
let query = this.query().where(where);
if (!noLimit) {
query = query.offset(offset).limit(count);
}
return await query
.orderBy("maintenance.createdAt", "ASC")
.getManyAndCount()
.then((res) => {
return res;
})
@ -30,13 +82,7 @@ export default abstract class MaintenanceService {
* @returns {Promise<maintenance>}
*/
static async getById(id: string): Promise<maintenance> {
return await dataSource
.getRepository(maintenance)
.createQueryBuilder("maintenance")
.leftJoinAndSelect("maintenance.equipment", "equipment")
.leftJoinAndSelect("maintenance.vehicle", "vehicle")
.leftJoinAndSelect("maintenance.wearable", "wearable")
.leftJoinAndSelect("maintenance.reports", "reports")
return await this.query()
.where({ id })
.getOneOrFail()
.then((res) => {