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