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

61 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../../data-source";
import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda";
2025-01-29 09:42:22 +01:00
import DatabaseActionException from "../../../exceptions/databaseActionException";
2025-01-05 14:14:00 +01:00
import InternalException from "../../../exceptions/internalException";
2024-10-11 14:44:09 +02:00
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) => {
2025-01-29 09:42:22 +01:00
throw new DatabaseActionException("SELECT", "protocolAgenda", err);
2024-10-11 14:44:09 +02:00
});
}
/**
* @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) => {
2025-01-29 09:42:22 +01:00
throw new DatabaseActionException("SELECT", "protocolAgenda", err);
2024-10-11 14:44:09 +02:00
});
}
/**
* @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);
});
}
2024-10-11 14:44:09 +02:00
}