49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { protocolVoting } from "../../../entity/club/protocol/protocolVoting";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
import InternalException from "../../../exceptions/internalException";
|
|
import { SynchronizeProtocolVotingCommand } from "./protocolVotingCommand";
|
|
|
|
export default abstract class ProtocolVotingCommandHandler {
|
|
/**
|
|
* @description create protocolVoting
|
|
* @param {number} protocolId
|
|
* @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 DatabaseActionException("CREATE", "protocolVoting", err);
|
|
});
|
|
}
|
|
/**
|
|
* @description sync protocolVoting
|
|
* @param {Array<SynchronizeProtocolVotingCommand>} syncProtocolVotings
|
|
* @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 DatabaseActionException("SYNC", "protocolVoting", err);
|
|
});
|
|
}
|
|
}
|