ff-admin-server/src/command/newsletterConfigCommandHandler.ts

31 lines
996 B
TypeScript
Raw Normal View History

2024-12-26 11:08:48 +01:00
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);
});
}
}