53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
import InternalException from "../../../exceptions/internalException";
|
|
import ProtocolAgendaService from "../../../service/club/protocol/protocolAgendaService";
|
|
import { SynchronizeProtocolAgendaCommand } from "./protocolAgendaCommand";
|
|
|
|
export default abstract class ProtocolAgendaCommandHandler {
|
|
/**
|
|
* @description create protocolAgenda
|
|
* @param {number} protocolId
|
|
* @returns {Promise<number>}
|
|
*/
|
|
static async create(protocolId: number): Promise<number> {
|
|
let count = await ProtocolAgendaService.getInstanceCount(protocolId);
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.insert()
|
|
.into(protocolAgenda)
|
|
.values({
|
|
topic: "",
|
|
context: "",
|
|
sort: count,
|
|
protocolId,
|
|
})
|
|
.execute()
|
|
.then((result) => {
|
|
return result.identifiers[0].id;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("CREATE", "protocolAgenda", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description sync protocolAgenda
|
|
* @param {Array<SynchronizeProtocolAgendaCommand>} syncProtocolAgenda
|
|
* @returns {Promise<void>}
|
|
*/
|
|
static async sync(syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.insert()
|
|
.into(protocolAgenda)
|
|
.values(syncProtocolAgenda)
|
|
.orUpdate(["topic", "context", "sort"], ["id"])
|
|
.execute()
|
|
.then(() => {})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SYNC", "protocolAgenda", err);
|
|
});
|
|
}
|
|
}
|