From aace2c7e6ccb6e74df83faac74c427d43bfaf79b Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Wed, 23 Apr 2025 15:06:54 -0700 Subject: Fix ReferenceError: nodemailerTransporter is not defined Part of https://github.com/lowercasename/gathio/pull/200 was migrating more code to use the shared init email function, but all the local usages of nodemailerTransporter were missed --- src/lib/handlebars.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/lib/handlebars.ts') diff --git a/src/lib/handlebars.ts b/src/lib/handlebars.ts index d5a8b6e..42f8010 100644 --- a/src/lib/handlebars.ts +++ b/src/lib/handlebars.ts @@ -1,4 +1,5 @@ import { Request } from "express"; +import { ExpressHandlebars } from "express-handlebars"; export const renderTemplate = async ( req: Request, @@ -21,3 +22,29 @@ export const renderTemplate = async ( ); }); }; + +export const renderEmail = async ( + hbsInstance: ExpressHandlebars, + templateName: string, + data: Record, +): Promise<{ html: string, text: string }> => { + const [html, text] = await Promise.all([ + hbsInstance.renderView( + `./views/emails/${templateName}Html.handlebars`, + { + cache: true, + layout: "email.handlebars", + ...data, + } + ), + hbsInstance.renderView( + `./views/emails/${templateName}Text.handlebars`, + { + cache: true, + layout: "email.handlebars", + ...data, + } + ), + ]); + return { html, text } +} -- cgit v1.2.3