command Handlers and schema update
This commit is contained in:
parent
0f6401953f
commit
7883bb7d7f
42 changed files with 1076 additions and 159 deletions
49
src/service/unit/damageReportService.ts
Normal file
49
src/service/unit/damageReportService.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue