2025-01-05 14:14:00 +01:00
|
|
|
import { dataSource } from "../../../data-source";
|
2025-02-15 10:59:54 +01:00
|
|
|
import { newsletterConfig } from "../../../entity/configuration/newsletterConfig";
|
2025-01-29 09:42:22 +01:00
|
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
2025-01-05 14:14:00 +01:00
|
|
|
import InternalException from "../../../exceptions/internalException";
|
2025-02-05 10:22:51 +01:00
|
|
|
import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "./newsletterConfigCommand";
|
2024-12-26 11:08:48 +01:00
|
|
|
|
|
|
|
export default abstract class NewsletterConfigCommandHandler {
|
|
|
|
/**
|
|
|
|
* @description set newsletterConfig
|
2025-01-05 14:29:31 +01:00
|
|
|
* @param {SetNewsletterConfigCommand} setNewsletterConfig
|
2025-02-05 10:22:51 +01:00
|
|
|
* @returns {Promise<void>}
|
2024-12-26 11:08:48 +01:00
|
|
|
*/
|
2025-02-05 10:22:51 +01:00
|
|
|
static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise<void> {
|
2024-12-26 11:08:48 +01:00
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.insert()
|
|
|
|
.into(newsletterConfig)
|
|
|
|
.values({
|
|
|
|
comTypeId: setNewsletterConfig.comTypeId,
|
|
|
|
config: setNewsletterConfig.config,
|
|
|
|
})
|
2025-03-24 09:19:11 +01:00
|
|
|
.orUpdate(["config"], ["comTypeId"])
|
2024-12-26 11:08:48 +01:00
|
|
|
.execute()
|
2025-02-05 10:22:51 +01:00
|
|
|
.then((result) => {})
|
2024-12-26 11:08:48 +01:00
|
|
|
.catch((err) => {
|
2025-01-29 09:42:22 +01:00
|
|
|
throw new DatabaseActionException("SET", "newsletterConfig", err);
|
2024-12-26 11:08:48 +01:00
|
|
|
});
|
|
|
|
}
|
2025-02-05 10:22:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
});
|
|
|
|
}
|
2024-12-26 11:08:48 +01:00
|
|
|
}
|