inspection fetch

This commit is contained in:
Julian Krauser 2025-07-09 12:57:37 +02:00
parent a0a8edf7af
commit 95b6cec66d
6 changed files with 189 additions and 21 deletions

View file

@ -1,3 +1,4 @@
import { IsNull } from "typeorm";
import { dataSource } from "../../../data-source";
import { inspection } from "../../../entity/unit/inspection/inspection";
import DatabaseActionException from "../../../exceptions/databaseActionException";
@ -16,6 +17,66 @@ export default abstract class InspectionService {
.leftJoinAndSelect("inspection.vehicle", "vehicle")
.leftJoinAndSelect("inspection.wearable", "wearable");
/**
* @description get all inspections sorted by next inspection not having newer
* @returns {Promise<Array<inspection>>}
*/
static async getAllSortedNotHavingNewer({
offset = 0,
count = 25,
noLimit = false,
}: {
offset?: number;
count?: number;
noLimit?: boolean;
}): Promise<[Array<inspection>, number]> {
let query = this.query().where({ hasNewer: false });
if (!noLimit) {
query = query.offset(offset).limit(count);
}
return await query
.orderBy("inspection.nextInspection", "ASC", "NULLS LAST")
.getManyAndCount()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "inspection", err);
});
}
/**
* @description get all inspections running
* @returns {Promise<Array<inspection>>}
*/
static async getAllRunning({
offset = 0,
count = 25,
noLimit = false,
}: {
offset?: number;
count?: number;
noLimit?: boolean;
}): Promise<[Array<inspection>, number]> {
let query = this.query().where({ finishedAt: IsNull() });
if (!noLimit) {
query = query.offset(offset).limit(count);
}
return await query
.orderBy("inspection.createdAt", "ASC")
.getManyAndCount()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "inspection", err);
});
}
/**
* @description get all inspections for related
* @returns {Promise<Array<inspection>>}