diff --git a/src/command/settings/newsletterConfig/newsletterConfigCommand.ts b/src/command/settings/newsletterConfig/newsletterConfigCommand.ts index be28649..f07de54 100644 --- a/src/command/settings/newsletterConfig/newsletterConfigCommand.ts +++ b/src/command/settings/newsletterConfig/newsletterConfigCommand.ts @@ -4,3 +4,7 @@ export interface SetNewsletterConfigCommand { comTypeId: number; config: NewsletterConfigType; } + +export interface DeleteNewsletterConfigCommand { + comTypeId: number; +} diff --git a/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts b/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts index 98d8e02..47fa295 100644 --- a/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts +++ b/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts @@ -2,15 +2,15 @@ import { dataSource } from "../../../data-source"; import { newsletterConfig } from "../../../entity/settings/newsletterConfig"; import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; -import { SetNewsletterConfigCommand } from "./newsletterConfigCommand"; +import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "./newsletterConfigCommand"; export default abstract class NewsletterConfigCommandHandler { /** * @description set newsletterConfig * @param {SetNewsletterConfigCommand} setNewsletterConfig - * @returns {Promise} + * @returns {Promise} */ - static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise { + static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise { return await dataSource .createQueryBuilder() .insert() @@ -21,11 +21,27 @@ export default abstract class NewsletterConfigCommandHandler { }) .orUpdate(["config"], "comTypeId") .execute() - .then((result) => { - return result.identifiers[0].id; - }) + .then((result) => {}) .catch((err) => { throw new DatabaseActionException("SET", "newsletterConfig", err); }); } + + /** + * @description delete newsletterConfig + * @param {DeleteNewsletterConfigCommand} deleteNewsletterConfig + * @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/settings/newsletterConfigController.ts b/src/controller/admin/settings/newsletterConfigController.ts index 7d0ff95..c476c54 100644 --- a/src/controller/admin/settings/newsletterConfigController.ts +++ b/src/controller/admin/settings/newsletterConfigController.ts @@ -2,7 +2,10 @@ import { Request, Response } from "express"; import NewsletterConfigService from "../../../service/settings/newsletterConfigService"; import NewsletterConfigFactory from "../../../factory/admin/settings/newsletterConfig"; import NewsletterConfigCommandHandler from "../../../command/settings/newsletterConfig/newsletterConfigCommandHandler"; -import { SetNewsletterConfigCommand } from "../../../command/settings/newsletterConfig/newsletterConfigCommand"; +import { + DeleteNewsletterConfigCommand, + SetNewsletterConfigCommand, +} from "../../../command/settings/newsletterConfig/newsletterConfigCommand"; /** * @description get all newsletterConfigs @@ -43,7 +46,24 @@ export async function setNewsletterConfig(req: Request, res: Response): Promise< comTypeId, config, }; - let id = await NewsletterConfigCommandHandler.set(createNewsletterConfig); + await NewsletterConfigCommandHandler.set(createNewsletterConfig); - res.send(id); + res.sendStatus(204); +} + +/** + * @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/settings/newsletterConfig.ts b/src/routes/admin/settings/newsletterConfig.ts index 94fe205..a874cc7 100644 --- a/src/routes/admin/settings/newsletterConfig.ts +++ b/src/routes/admin/settings/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;