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>} */ static async getAll(): Promise> { 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} */ static async getById(id: string): Promise { 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); }); } }