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>} */ static async getAll(): Promise> { 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} */ static async getById(id: string): Promise { 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); }); } }