command Handlers and schema update

This commit is contained in:
Julian Krauser 2025-05-29 10:31:40 +02:00
parent 0f6401953f
commit 7883bb7d7f
42 changed files with 1076 additions and 159 deletions

View file

@ -1,49 +0,0 @@
import { dataSource } from "../../data-source";
import { damageReport } from "../../entity/unit/damageReport";
import DatabaseActionException from "../../exceptions/databaseActionException";
export default abstract class DamageReportService {
/**
* @description get all damageReports
* @returns {Promise<Array<damageReport>>}
*/
static async getAll(): Promise<Array<damageReport>> {
return await dataSource
.getRepository(damageReport)
.createQueryBuilder("damageReport")
.leftJoinAndSelect("damageReport.equipment", "equipment")
.leftJoinAndSelect("damageReport.vehicle", "vehicle")
.leftJoinAndSelect("damageReport.wearable", "wearable")
.leftJoinAndSelect("damageReport.maintenance", "maintenance")
.orderBy("type", "ASC")
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "damageReport", err);
});
}
/**
* @description get damageReport by id
* @returns {Promise<damageReport>}
*/
static async getById(id: string): Promise<damageReport> {
return await dataSource
.getRepository(damageReport)
.createQueryBuilder("damageReport")
.leftJoinAndSelect("damageReport.equipment", "equipment")
.leftJoinAndSelect("damageReport.vehicle", "vehicle")
.leftJoinAndSelect("damageReport.wearable", "wearable")
.leftJoinAndSelect("damageReport.maintenance", "maintenance")
.where({ id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "damageReport", err);
});
}
}