import { dataSource } from "../../data-source"; import { calendar } from "../../entity/club/calendar"; import InternalException from "../../exceptions/internalException"; export default abstract class CalendarService { /** * @description get all calendars * @returns {Promise>} */ static async getAll(): Promise> { return await dataSource .getRepository(calendar) .createQueryBuilder("calendar") .leftJoinAndSelect("calendar.type", "type") .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("calendars not found", err); }); } /** * @description get calendar by id * @returns {Promise} */ static async getById(id: string): Promise { return await dataSource .getRepository(calendar) .createQueryBuilder("calendar") .leftJoinAndSelect("calendar.type", "type") .where("calendar.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new InternalException("calendar not found by id", err); }); } /** * @description get calendar by types * @returns {Promise>} */ static async getByTypes(types: Array, addNscdr: boolean = false): Promise> { const query = dataSource .getRepository(calendar) .createQueryBuilder("calendar") .leftJoinAndSelect("calendar.type", "type") .where("type.id IN (:...types)", { types: types }); if (addNscdr) { query.orWhere("type.nscdr = :nscdr", { nscdr: true }); } return await query .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("calendars not found by types", err); }); } /** * @description get calendar by types nscdr * @returns {Promise>} */ static async getByTypeNSCDR(): Promise> { return await dataSource .getRepository(calendar) .createQueryBuilder("calendar") .leftJoinAndSelect("calendar.type", "type") .where("type.nscdr = :nscdr", { nscdr: true }) .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("calendars not found by type nscdr", err); }); } }