31 lines
996 B
TypeScript
31 lines
996 B
TypeScript
|
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);
|
||
|
});
|
||
|
}
|
||
|
}
|