import { dataSource } from "../../../data-source"; import { protocol } from "../../../entity/club/protocol/protocol"; import InternalException from "../../../exceptions/internalException"; import { CreateProtocolCommand, SynchronizeProtocolCommand } from "./protocolCommand"; export default abstract class ProtocolCommandHandler { /** * @description create protocol * @param {CreateProtocolCommand} createProtocol * @returns {Promise} */ static async create(createProtocol: CreateProtocolCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(protocol) .values({ title: createProtocol.title, date: createProtocol.date, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed creating protocol", err); }); } /** * @description sync protocol * @param {SynchronizeProtocolCommand} syncProtocol * @returns {Promise} */ static async sync(syncProtocol: SynchronizeProtocolCommand): Promise { return await dataSource .createQueryBuilder() .update(protocol) .set({ title: syncProtocol.title, date: syncProtocol.date, starttime: syncProtocol.starttime, endtime: syncProtocol.endtime, summary: syncProtocol.summary, }) .where("id = :id", { id: syncProtocol.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed creating protocol", err); }); } }