import { dataSource } from "../data-source"; import { protocol } from "../entity/protocol"; import InternalException from "../exceptions/internalException"; export default abstract class ProtocolService { /** * @description get all protocols * @returns {Promise<[Array, number]>} */ static async getAll(offset: number = 0, count: number = 25): Promise<[Array, number]> { return await dataSource .getRepository(protocol) .createQueryBuilder("protocol") .offset(offset) .limit(count) .orderBy("date") .getManyAndCount() .then((res) => { return res; }) .catch((err) => { throw new InternalException("protocols not found", err); }); } /** * @description get protocol by id * @returns {Promise} */ static async getById(id: number): Promise { return await dataSource .getRepository(protocol) .createQueryBuilder("protocol") .where("protocol.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new InternalException("protocol not found by id", err); }); } }