import { dataSource } from "../data-source"; import { calendarType } from "../entity/calendarType"; import InternalException from "../exceptions/internalException"; export default abstract class CalendarTypeService { /** * @description get all calendar types * @returns {Promise>} */ static async getAll(): Promise> { return await dataSource .getRepository(calendarType) .createQueryBuilder("calendarType") .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("calendarTypes not found", err); }); } /** * @description get calendar type by id * @returns {Promise} */ static async getById(id: number): Promise { return await dataSource .getRepository(calendarType) .createQueryBuilder("calendarType") .where("calendarType.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new InternalException("calendarType not found by id", err); }); } /** * @description get calendar by names * @returns {Promise>} */ static async getByTypes(names: Array): Promise> { return await dataSource .getRepository(calendarType) .createQueryBuilder("calendarType") .where("calendarType.type IN (:...names)", { names: names }) .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("calendarTypes not found by names", err); }); } }