56 lines
1.9 KiB
TypeScript
56 lines
1.9 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 ProtocolVotingService from "../../../service/club/protocol/protocolVotingService";
|
|
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> {
|
|
let count = await ProtocolVotingService.getInstanceCount(protocolId);
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.insert()
|
|
.into(protocolVoting)
|
|
.values({
|
|
topic: "",
|
|
context: "",
|
|
sort: count,
|
|
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
|
|
.transaction(async (transactionalEntityManager) => {
|
|
for (const voting of syncProtocolVotings) {
|
|
await transactionalEntityManager
|
|
.createQueryBuilder()
|
|
.update(protocolVoting)
|
|
.set(voting)
|
|
.where({ id: voting.id })
|
|
.execute();
|
|
}
|
|
})
|
|
.then(() => {})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SYNC", "protocolVoting", err);
|
|
});
|
|
}
|
|
}
|