patches v1.3.1 #59

Merged
jkeffects merged 5 commits from develop into main 2025-02-07 08:41:31 +00:00
4 changed files with 58 additions and 9 deletions
Showing only changes of commit 3f3ad9ca58 - Show all commits

View file

@ -4,3 +4,7 @@ export interface SetNewsletterConfigCommand {
comTypeId: number;
config: NewsletterConfigType;
}
export interface DeleteNewsletterConfigCommand {
comTypeId: number;
}

View file

@ -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<number>}
* @returns {Promise<void>}
*/
static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise<number> {
static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise<void> {
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<void>}
*/
static async delete(deleteNewsletterConfig: DeleteNewsletterConfigCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(newsletterConfig)
.where("comTypeId = :comTypeId", { comTypeId: deleteNewsletterConfig.comTypeId })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed setting newsletterConfig", err);
});
}
}

View file

@ -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<any> {
const comTypeId = parseInt(req.params.comTypeId);
let deleteNewsletterConfig: DeleteNewsletterConfigCommand = {
comTypeId: comTypeId,
};
await NewsletterConfigCommandHandler.delete(deleteNewsletterConfig);
res.sendStatus(204);
}

View file

@ -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;