newsletter config CRUD

This commit is contained in:
Julian Krauser 2024-12-26 11:08:48 +01:00
parent 01ce3fdd39
commit 7d36ed3121
14 changed files with 274 additions and 1 deletions

View file

@ -0,0 +1,6 @@
import { NewsletterConfigType } from "../enums/newsletterConfigType";
export interface SetNewsletterConfigCommand {
comTypeId: number;
config: NewsletterConfigType;
}

View file

@ -0,0 +1,30 @@
import { dataSource } from "../data-source";
import { newsletterConfig } from "../entity/newsletterConfig";
import InternalException from "../exceptions/internalException";
import { SetNewsletterConfigCommand } from "./newsletterConfigCommand";
export default abstract class NewsletterConfigCommandHandler {
/**
* @description set newsletterConfig
* @param SetNewsletterConfigCommand
* @returns {Promise<number>}
*/
static async setConfig(setNewsletterConfig: SetNewsletterConfigCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(newsletterConfig)
.values({
comTypeId: setNewsletterConfig.comTypeId,
config: setNewsletterConfig.config,
})
.orUpdate(["config"], "comTypeId")
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed setting newsletterConfig", err);
});
}
}