diff --git a/src/controller/admin/templateController.ts b/src/controller/admin/templateController.ts index 9c8a2a0..9f867f9 100644 --- a/src/controller/admin/templateController.ts +++ b/src/controller/admin/templateController.ts @@ -48,6 +48,35 @@ export async function createTemplate(req: Request, res: Response): Promise res.status(200).send(id); } +/** + * @description clone template + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function cloneTemplate(req: Request, res: Response): Promise { + const cloneId = req.body.cloneId; + + const { template, description, design, html } = await TemplateService.getById(cloneId); + + let createTemplate: CreateTemplateCommand = { + template: "", + description: "", + }; + let id = await TemplateCommandHandler.create(createTemplate); + + let updateTemplate: UpdateTemplateCommand = { + id: id, + template: template + " - Kopie", + description: description, + design: design, + html: html, + }; + await TemplateCommandHandler.update(updateTemplate); + + res.status(200).send(id); +} + /** * @description update template * @param req {Request} Express req object diff --git a/src/routes/admin/template.ts b/src/routes/admin/template.ts index 1653956..492837e 100644 --- a/src/routes/admin/template.ts +++ b/src/routes/admin/template.ts @@ -1,5 +1,6 @@ import express, { Request, Response } from "express"; import { + cloneTemplate, createTemplate, deleteTemplate, getAllTemplates, @@ -26,6 +27,14 @@ router.post( } ); +router.post( + "/clone", + PermissionHelper.passCheckMiddleware("create", "settings", "template"), + async (req: Request, res: Response) => { + await cloneTemplate(req, res); + } +); + router.patch( "/:id", PermissionHelper.passCheckMiddleware("update", "settings", "template"),