42 lines
1.1 KiB
TypeScript
42 lines
1.1 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 wearable types
|
||
|
* @returns {Promise<Array<wearable>>}
|
||
|
*/
|
||
|
static async getAll(): Promise<Array<wearable>> {
|
||
|
return await dataSource
|
||
|
.getRepository(wearable)
|
||
|
.createQueryBuilder("wearable")
|
||
|
.orderBy("type", "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")
|
||
|
.where({ id })
|
||
|
.getOneOrFail()
|
||
|
.then((res) => {
|
||
|
return res;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new DatabaseActionException("SELECT", "wearable", err);
|
||
|
});
|
||
|
}
|
||
|
}
|