2025-01-05 14:14:00 +01:00
|
|
|
import { dataSource } from "../../../data-source";
|
|
|
|
import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda";
|
2025-01-29 09:42:22 +01:00
|
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
2025-01-05 14:14:00 +01:00
|
|
|
import InternalException from "../../../exceptions/internalException";
|
2024-10-13 15:48:01 +02:00
|
|
|
import { SynchronizeProtocolAgendaCommand } from "./protocolAgendaCommand";
|
|
|
|
|
|
|
|
export default abstract class ProtocolAgendaCommandHandler {
|
2024-10-15 16:25:42 +02:00
|
|
|
/**
|
|
|
|
* @description create protocolAgenda
|
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(protocolAgenda)
|
|
|
|
.values({
|
|
|
|
topic: "",
|
|
|
|
context: "",
|
|
|
|
protocolId,
|
|
|
|
})
|
|
|
|
.execute()
|
|
|
|
.then((result) => {
|
|
|
|
return result.identifiers[0].id;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2025-01-29 09:42:22 +01:00
|
|
|
throw new DatabaseActionException("CREATE", "protocolAgenda", err);
|
2024-10-15 16:25:42 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-13 15:48:01 +02:00
|
|
|
/**
|
|
|
|
* @description sync protocolAgenda
|
2025-01-05 14:29:31 +01:00
|
|
|
* @param {Array<SynchronizeProtocolAgendaCommand>} syncProtocolAgenda
|
2024-10-13 15:48:01 +02:00
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
static async sync(syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
|
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.insert()
|
|
|
|
.into(protocolAgenda)
|
|
|
|
.values(syncProtocolAgenda)
|
|
|
|
.orUpdate(["topic", "context"], ["id"])
|
|
|
|
.execute()
|
|
|
|
.then(() => {})
|
|
|
|
.catch((err) => {
|
2025-01-29 09:42:22 +01:00
|
|
|
throw new DatabaseActionException("SYNC", "protocolAgenda", err);
|
2024-10-13 15:48:01 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|