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