ff-admin-server/src/service/unit/wearable/wearableService.ts

44 lines
1.3 KiB
TypeScript

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