service base
This commit is contained in:
parent
8c81c8f336
commit
2433120e26
13 changed files with 494 additions and 0 deletions
41
src/service/unit/equipment/equipmentService.ts
Normal file
41
src/service/unit/equipment/equipmentService.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
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 types
|
||||
* @returns {Promise<Array<equipment>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<equipment>> {
|
||||
return await dataSource
|
||||
.getRepository(equipment)
|
||||
.createQueryBuilder("equipment")
|
||||
.orderBy("type", "ASC")
|
||||
.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")
|
||||
.where({ id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "equipment", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue