ff-admin-server/src/service/club/protocol/protocolAgendaService.ts

60 lines
1.9 KiB
TypeScript

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);
});
}
/**
* @description get count of exisiting protocolAgenda by protocolId
* @returns {Promise<number>}
*/
static async getInstanceCount(protocolId: number): Promise<number> {
return await dataSource
.getRepository(protocolAgenda)
.createQueryBuilder("protocolAgenda")
.where({ protocolId })
.getCount()
.then((res) => {
return res;
})
.catch((err) => {
throw new DatabaseActionException("COUNT", "protocolAgenda", err);
});
}
}