import { dataSource } from "../data-source"; import { communicationType } from "../entity/communicationType"; import InternalException from "../exceptions/internalException"; import { CreateCommunicationTypeCommand, DeleteCommunicationTypeCommand, UpdateCommunicationTypeCommand, } from "./communicationTypeCommand"; export default abstract class CommunicationTypeCommandHandler { /** * @description create communicationType * @param CreateCommunicationTypeCommand * @returns {Promise} */ static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(communicationType) .values({ type: createCommunicationType.type, useColumns: createCommunicationType.useColumns, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed creating communicationType", err); }); } /** * @description update communicationType * @param UpdateCommunicationTypeCommand * @returns {Promise} */ static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise { return await dataSource .createQueryBuilder() .update(communicationType) .set({ type: updateCommunicationType.type, useColumns: updateCommunicationType.useColumns, }) .where("id = :id", { id: updateCommunicationType.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed updating communicationType", err); }); } /** * @description delete communicationType * @param DeleteCommunicationTypeCommand * @returns {Promise} */ static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(communicationType) .where("id = :id", { id: deletCommunicationType.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed deleting communicationType", err); }); } }