ff-admin-server/src/command/club/protocol/protocolVotingCommandHandler.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../../data-source";
import { protocolVoting } from "../../../entity/club/protocol/protocolVoting";
import InternalException from "../../../exceptions/internalException";
2024-10-13 15:48:01 +02:00
import { SynchronizeProtocolVotingCommand } from "./protocolVotingCommand";
export default abstract class ProtocolVotingCommandHandler {
2024-10-15 16:25:42 +02:00
/**
* @description create protocolVoting
2025-01-05 14:29:31 +01:00
* @param {number} protocolId
2024-10-15 16:25:42 +02:00
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolVoting)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
2024-10-13 15:48:01 +02:00
/**
* @description sync protocolVoting
2025-01-05 14:29:31 +01:00
* @param {Array<SynchronizeProtocolVotingCommand>} syncProtocolVotings
2024-10-13 15:48:01 +02:00
* @returns {Promise<void>}
*/
static async sync(syncProtocolVotings: Array<SynchronizeProtocolVotingCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolVoting)
.values(syncProtocolVotings)
.orUpdate(["topic", "context", "favour", "abstain", "against"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}