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; comTypeId: number;
config: NewsletterConfigType; 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 { newsletterConfig } from "../../../entity/settings/newsletterConfig";
import DatabaseActionException from "../../../exceptions/databaseActionException"; import DatabaseActionException from "../../../exceptions/databaseActionException";
import InternalException from "../../../exceptions/internalException"; import InternalException from "../../../exceptions/internalException";
import { SetNewsletterConfigCommand } from "./newsletterConfigCommand"; import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "./newsletterConfigCommand";
export default abstract class NewsletterConfigCommandHandler { export default abstract class NewsletterConfigCommandHandler {
/** /**
* @description set newsletterConfig * @description set newsletterConfig
* @param {SetNewsletterConfigCommand} setNewsletterConfig * @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 return await dataSource
.createQueryBuilder() .createQueryBuilder()
.insert() .insert()
@ -21,11 +21,27 @@ export default abstract class NewsletterConfigCommandHandler {
}) })
.orUpdate(["config"], "comTypeId") .orUpdate(["config"], "comTypeId")
.execute() .execute()
.then((result) => { .then((result) => {})
return result.identifiers[0].id;
})
.catch((err) => { .catch((err) => {
throw new DatabaseActionException("SET", "newsletterConfig", 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 NewsletterConfigService from "../../../service/settings/newsletterConfigService";
import NewsletterConfigFactory from "../../../factory/admin/settings/newsletterConfig"; import NewsletterConfigFactory from "../../../factory/admin/settings/newsletterConfig";
import NewsletterConfigCommandHandler from "../../../command/settings/newsletterConfig/newsletterConfigCommandHandler"; 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 * @description get all newsletterConfigs
@ -43,7 +46,24 @@ export async function setNewsletterConfig(req: Request, res: Response): Promise<
comTypeId, comTypeId,
config, 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 express, { Request, Response } from "express";
import { import {
deleteNewsletterConfig,
getAllNewsletterConfigs, getAllNewsletterConfigs,
getNewsletterConfigById, getNewsletterConfigById,
setNewsletterConfig, 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; export default router;