newsletter config CRUD
This commit is contained in:
parent
01ce3fdd39
commit
7d36ed3121
14 changed files with 274 additions and 1 deletions
6
src/command/newsletterConfigCommand.ts
Normal file
6
src/command/newsletterConfigCommand.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { NewsletterConfigType } from "../enums/newsletterConfigType";
|
||||
|
||||
export interface SetNewsletterConfigCommand {
|
||||
comTypeId: number;
|
||||
config: NewsletterConfigType;
|
||||
}
|
30
src/command/newsletterConfigCommandHandler.ts
Normal file
30
src/command/newsletterConfigCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue