41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { dataSource } from "../data-source";
|
|
import { protocolVoting } from "../entity/protocolVoting";
|
|
import InternalException from "../exceptions/internalException";
|
|
|
|
export default abstract class ProtocolVotingService {
|
|
/**
|
|
* @description get all protocolVotingss
|
|
* @returns {Promise<Array<protocolVoting>>}
|
|
*/
|
|
static async getAll(protocolId: number): Promise<Array<protocolVoting>> {
|
|
return await dataSource
|
|
.getRepository(protocolVoting)
|
|
.createQueryBuilder("protocolVotings")
|
|
.where("protocolVotings.protocolId = :protocolId", { protocolId })
|
|
.getMany()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new InternalException("protocolVotings not found", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description get protocolVoting by id
|
|
* @returns {Promise<protocolVoting>}
|
|
*/
|
|
static async getById(id: number): Promise<protocolVoting> {
|
|
return await dataSource
|
|
.getRepository(protocolVoting)
|
|
.createQueryBuilder("protocolVotings")
|
|
.where("protocolVotings.id = :id", { id: id })
|
|
.getOneOrFail()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new InternalException("protocolVoting not found by id", err);
|
|
});
|
|
}
|
|
}
|