reintroduce newsletter config

This commit is contained in:
Julian Krauser 2025-02-05 10:22:51 +01:00
parent 2ce56a49bb
commit 3f3ad9ca58
4 changed files with 58 additions and 9 deletions

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);
});
}
}