import { dataSource } from "../data-source"; import { award } from "../entity/award"; import { user } from "../entity/user"; import InternalException from "../exceptions/internalException"; export default abstract class AwardService { /** * @description get all awards * @returns {Promise>} */ static async getAll(): Promise> { return await dataSource .getRepository(award) .createQueryBuilder("award") .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("awards not found", err); }); } /** * @description get award by id * @returns {Promise} */ static async getById(id: number): Promise { return await dataSource .getRepository(award) .createQueryBuilder("award") .andWhere("award.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new InternalException("award not found by id", err); }); } // /** // * @description get members assigned to award // * @returns {Promise>} // */ // static async getMembersByAwardId(id: number): Promise> { // return await dataSource // .getRepository(award) // .createQueryBuilder("award") // .leftJoinAndSelect("award.members", "members") // .andWhere("award.id = :id", { id: id }) // .getOneOrFail() // .then((res) => { // return []; // }) // .catch((err) => { // throw new InternalException("award assigned members not found by id", err); // }); // } }