import { dataSource } from "../../../data-source"; import { equipment } from "../../../entity/unit/equipment/equipment"; import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class EquipmentService { /** * @description get all equipment * @returns {Promise>} */ static async getAll(): Promise> { return await dataSource .getRepository(equipment) .createQueryBuilder("equipment") .leftJoinAndSelect("equipment.equipmentType", "equipmenttype") .orderBy("name", "ASC") .getMany() .then((res) => { return res; }) .catch((err) => { throw new DatabaseActionException("SELECT", "equipment", err); }); } /** * @description get equipment by id * @returns {Promise} */ static async getById(id: string): Promise { return await dataSource .getRepository(equipment) .createQueryBuilder("equipment") .leftJoinAndSelect("equipment.equipmentType", "equipmenttype") .where({ id }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new DatabaseActionException("SELECT", "equipment", err); }); } }