import { dataSource } from "../../../data-source";
import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda";
import DatabaseActionException from "../../../exceptions/databaseActionException";
import InternalException from "../../../exceptions/internalException";

export default abstract class ProtocolAgendaService {
  /**
   * @description get all protocolAgendas
   * @returns {Promise<Array<protocolAgenda>>}
   */
  static async getAll(protocolId: number): Promise<Array<protocolAgenda>> {
    return await dataSource
      .getRepository(protocolAgenda)
      .createQueryBuilder("protocolAgenda")
      .where("protocolAgenda.protocolId = :protocolId", { protocolId })
      .getMany()
      .then((res) => {
        return res;
      })
      .catch((err) => {
        throw new DatabaseActionException("SELECT", "protocolAgenda", err);
      });
  }

  /**
   * @description get protocolAgenda by id
   * @returns {Promise<protocolAgenda>}
   */
  static async getById(id: number): Promise<protocolAgenda> {
    return await dataSource
      .getRepository(protocolAgenda)
      .createQueryBuilder("protocolAgenda")
      .where("protocolAgenda.id = :id", { id: id })
      .getOneOrFail()
      .then((res) => {
        return res;
      })
      .catch((err) => {
        throw new DatabaseActionException("SELECT", "protocolAgenda", err);
      });
  }
}