template storing
This commit is contained in:
parent
98477eafde
commit
160d82459d
12 changed files with 386 additions and 1 deletions
18
src/command/templateCommand.ts
Normal file
18
src/command/templateCommand.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
export interface CreateTemplateCommand {
|
||||
template: string;
|
||||
description: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateTemplateCommand {
|
||||
id: number;
|
||||
template: string;
|
||||
description: string | null;
|
||||
design: object;
|
||||
headerHTML: string;
|
||||
bodyHTML: string;
|
||||
footerHTML: string;
|
||||
}
|
||||
|
||||
export interface DeleteTemplateCommand {
|
||||
id: number;
|
||||
}
|
72
src/command/templateCommandHandler.ts
Normal file
72
src/command/templateCommandHandler.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { template } from "../entity/template";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { CreateTemplateCommand, DeleteTemplateCommand, UpdateTemplateCommand } from "./templateCommand";
|
||||
|
||||
export default abstract class TemplateCommandHandler {
|
||||
/**
|
||||
* @description create template
|
||||
* @param CreateTemplateCommand
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createTemplate: CreateTemplateCommand): Promise<number> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(template)
|
||||
.values({
|
||||
template: createTemplate.template,
|
||||
description: createTemplate.description,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
return result.identifiers[0].id;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed creating template", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update template
|
||||
* @param UpdateTemplateCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateTemplate: UpdateTemplateCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(template)
|
||||
.set({
|
||||
template: updateTemplate.template,
|
||||
description: updateTemplate.description,
|
||||
design: updateTemplate.design,
|
||||
headerHTML: updateTemplate.headerHTML,
|
||||
bodyHTML: updateTemplate.bodyHTML,
|
||||
footerHTML: updateTemplate.footerHTML,
|
||||
})
|
||||
.where("id = :id", { id: updateTemplate.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating template", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete template
|
||||
* @param DeleteTemplateCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deletTemplate: DeleteTemplateCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(template)
|
||||
.where("id = :id", { id: deletTemplate.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting template", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue