diff --git a/README.md b/README.md index 16c0e8b..b735772 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ curl -X POST http://localhost:3000/api/v1/email \ "language": "en", "data": { "name": "John Doe", - "barcode_url": "https://barcodeapi.org/api/8/12345670?", + "barcode_content": "0123456789", "link": "https://portal.lauf-fuer-kaya.de/" } }' @@ -95,7 +95,7 @@ The project uses: ### Welcome Email - Languages: 🇬🇧 English, 🇩🇪 German -- Variables: `name`, `link`, `barcode_url` +- Variables: `name`, `link`, `barcode_content` ### Password Reset - Languages: 🇬🇧 English, 🇩🇪 German diff --git a/src/routes/email.ts b/src/routes/email.ts index 99600be..d69d54a 100644 --- a/src/routes/email.ts +++ b/src/routes/email.ts @@ -17,17 +17,22 @@ const sendEmailSchema = z.object({ }) emailRouter.post('/', zValidator('json', sendEmailSchema), async (c) => { - const { to, subject, templateName, language, data } = c.req.valid('json') - + let { to, subject, templateName, language, data } = c.req.valid('json') + try { const template = getEmailTemplate(templateName, language as Language) + if (templateName === "welcome") { + if (data.barcode_content === "0123456789") { + data.barcode_url = "https://barcodeapi.org/api/128/0123456789?" + } + } await emailService.sendEmail({ to, subject, html: template.html(data), text: template.text(data) }) - + return c.json({ success: true }) } catch (error) { return c.json({ success: false, error: (error as Error).message }, 400) diff --git a/src/templates/welcome/de.html b/src/templates/welcome/de.html index 2424a5c..104a962 100644 --- a/src/templates/welcome/de.html +++ b/src/templates/welcome/de.html @@ -2,11 +2,6 @@
- diff --git a/src/templates/welcome/en.html b/src/templates/welcome/en.html index 6fd93a1..7e045e6 100644 --- a/src/templates/welcome/en.html +++ b/src/templates/welcome/en.html @@ -2,11 +2,6 @@ -