diff --git a/src/command/newsletterConfigCommand.ts b/src/command/newsletterConfigCommand.ts index 861e3e3..011bc11 100644 --- a/src/command/newsletterConfigCommand.ts +++ b/src/command/newsletterConfigCommand.ts @@ -4,3 +4,7 @@ export interface SetNewsletterConfigCommand { comTypeId: number; config: NewsletterConfigType; } + +export interface DeleteNewsletterConfigCommand { + comTypeId: number; +} diff --git a/src/command/newsletterConfigCommandHandler.ts b/src/command/newsletterConfigCommandHandler.ts index d054c38..6f6b948 100644 --- a/src/command/newsletterConfigCommandHandler.ts +++ b/src/command/newsletterConfigCommandHandler.ts @@ -1,7 +1,7 @@ import { dataSource } from "../data-source"; import { newsletterConfig } from "../entity/newsletterConfig"; import InternalException from "../exceptions/internalException"; -import { SetNewsletterConfigCommand } from "./newsletterConfigCommand"; +import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "./newsletterConfigCommand"; export default abstract class NewsletterConfigCommandHandler { /** @@ -9,7 +9,7 @@ export default abstract class NewsletterConfigCommandHandler { * @param SetNewsletterConfigCommand * @returns {Promise} */ - static async setConfig(setNewsletterConfig: SetNewsletterConfigCommand): Promise { + static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise { return await dataSource .createQueryBuilder() .insert() @@ -27,4 +27,21 @@ export default abstract class NewsletterConfigCommandHandler { 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); + }); + } } diff --git a/src/controller/admin/newsletterConfigController.ts b/src/controller/admin/newsletterConfigController.ts index 790d093..3abe4b5 100644 --- a/src/controller/admin/newsletterConfigController.ts +++ b/src/controller/admin/newsletterConfigController.ts @@ -2,7 +2,7 @@ import { Request, Response } from "express"; import NewsletterConfigService from "../../service/newsletterConfigService"; import NewsletterConfigFactory from "../../factory/admin/newsletterConfig"; import NewsletterConfigCommandHandler from "../../command/newsletterConfigCommandHandler"; -import { SetNewsletterConfigCommand } from "../../command/newsletterConfigCommand"; +import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "../../command/newsletterConfigCommand"; /** * @description get all newsletterConfigs @@ -43,7 +43,24 @@ export async function setNewsletterConfig(req: Request, res: Response): Promise< comTypeId, config, }; - let id = await NewsletterConfigCommandHandler.setConfig(createNewsletterConfig); + let id = await NewsletterConfigCommandHandler.set(createNewsletterConfig); res.send(id); } + +/** + * @description delete award + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteNewsletterConfig(req: Request, res: Response): Promise { + const comTypeId = parseInt(req.params.comTypeId); + + let deleteNewsletterConfig: DeleteNewsletterConfigCommand = { + comTypeId: comTypeId, + }; + await NewsletterConfigCommandHandler.delete(deleteNewsletterConfig); + + res.sendStatus(204); +} diff --git a/src/routes/admin/newsletterConfig.ts b/src/routes/admin/newsletterConfig.ts index c1be19d..05cb0e9 100644 --- a/src/routes/admin/newsletterConfig.ts +++ b/src/routes/admin/newsletterConfig.ts @@ -1,5 +1,6 @@ import express, { Request, Response } from "express"; import { + deleteNewsletterConfig, getAllNewsletterConfigs, getNewsletterConfigById, setNewsletterConfig, @@ -24,4 +25,12 @@ router.put( } ); +router.delete( + "/:comTypeId", + PermissionHelper.passCheckMiddleware("create", "settings", "newsletter_config"), + async (req: Request, res: Response) => { + await deleteNewsletterConfig(req, res); + } +); + export default router;