import { dataSource } from "../data-source"; import { newsletterConfig } from "../entity/newsletterConfig"; import InternalException from "../exceptions/internalException"; import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "./newsletterConfigCommand"; export default abstract class NewsletterConfigCommandHandler { /** * @description set newsletterConfig * @param SetNewsletterConfigCommand * @returns {Promise} */ static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(newsletterConfig) .values({ comTypeId: setNewsletterConfig.comTypeId, config: setNewsletterConfig.config, }) .orUpdate(["config"], "comTypeId") .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed setting newsletterConfig", err); }); } /** * @description delete newsletterConfig * @param number * @returns {Promise} */ static async delete(deleteNewsletterConfig: DeleteNewsletterConfigCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(newsletterConfig) .where("comTypeId = :comTypeId", { comTypeId: deleteNewsletterConfig.comTypeId }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed setting newsletterConfig", err); }); } }