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

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-05-28 17:06:56 +02:00
import { dataSource } from "../../../data-source";
import { wearable } from "../../../entity/unit/wearable/wearable";
import DatabaseActionException from "../../../exceptions/databaseActionException";
export default abstract class WearableService {
/**
2025-05-28 17:32:07 +02:00
* @description get all wearables
2025-05-28 17:06:56 +02:00
* @returns {Promise<Array<wearable>>}
*/
static async getAll(): Promise<Array<wearable>> {
return await dataSource
.getRepository(wearable)
.createQueryBuilder("wearable")
2025-05-28 17:32:07 +02:00
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
2025-05-28 18:30:00 +02:00
.leftJoinAndSelect("wearable.wearer", "wearer")
2025-05-28 17:32:07 +02:00
.orderBy("name", "ASC")
2025-05-28 17:06:56 +02:00
.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")
2025-05-28 17:32:07 +02:00
.leftJoinAndSelect("wearable.wearableType", "wearabletype")
2025-05-28 17:06:56 +02:00
.where({ id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("SELECT", "wearable", err);
});
}
}