import { dataSource } from "../data-source"; import { protocolAgenda } from "../entity/protocolAgenda"; import InternalException from "../exceptions/internalException"; import { SynchronizeProtocolAgendaCommand } from "./protocolAgendaCommand"; export default abstract class ProtocolAgendaCommandHandler { /** * @description create protocolAgenda * @param {number} * @returns {Promise} */ static async create(protocolId: number): Promise { return await dataSource .createQueryBuilder() .insert() .into(protocolAgenda) .values({ topic: "", context: "", protocolId, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed creating protocol", err); }); } /** * @description sync protocolAgenda * @param {Array} * @returns {Promise} */ static async sync(syncProtocolAgenda: Array): Promise { return await dataSource .createQueryBuilder() .insert() .into(protocolAgenda) .values(syncProtocolAgenda) .orUpdate(["topic", "context"], ["id"]) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed creating protocol", err); }); } }