summaryrefslogtreecommitdiff
path: root/src/lib/handlebars.ts
diff options
context:
space:
mode:
authorRaphael Kabo <raphaelkabo@hey.com>2023-10-07 14:30:24 +0100
committerRaphael Kabo <raphaelkabo@hey.com>2023-10-07 15:38:47 +0100
commitb795d07ed7a1b705b72b171f8e8de267a720223b (patch)
treeb8ae3df8dbb89f839f29328e817f030dc22b89f8 /src/lib/handlebars.ts
parent9341659fd7a791d77454dd33743e42d952dbd202 (diff)
refactor: event form and api routes
Diffstat (limited to 'src/lib/handlebars.ts')
-rw-r--r--src/lib/handlebars.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/handlebars.ts b/src/lib/handlebars.ts
new file mode 100644
index 0000000..d5a8b6e
--- /dev/null
+++ b/src/lib/handlebars.ts
@@ -0,0 +1,23 @@
+import { Request } from "express";
+
+export const renderTemplate = async (
+ req: Request,
+ templateName: string,
+ data: Record<string, unknown>,
+): Promise<string> => {
+ return new Promise<string>((resolve, reject) => {
+ req.app
+ .get("hbsInstance")
+ .renderView(
+ `./views/emails/${templateName}.handlebars`,
+ data,
+ (err: any, html: string) => {
+ if (err) {
+ console.error(err);
+ reject(err);
+ }
+ resolve(html);
+ },
+ );
+ });
+};