From a2385269ba52f54230bfb40230b3bd5a0898fd36 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Sun, 12 Mar 2023 22:29:02 +0100 Subject: [PATCH] fix: add question email --- functions/send-emails/index.ts | 12 ++++++++++-- services/mail.ts | 8 +++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/functions/send-emails/index.ts b/functions/send-emails/index.ts index 76fb02f..541d974 100644 --- a/functions/send-emails/index.ts +++ b/functions/send-emails/index.ts @@ -38,6 +38,7 @@ Handlebars.registerHelper('i18n', interface RequestPayload { recipients: {[email: string]: {[key: string]: string}}; + question: string; locale: string; action: "invite" | "admin"; } @@ -55,7 +56,7 @@ const handler: Handler = async (event) => { }; } - const {recipients, action, locale} = JSON.parse(event.body) as RequestPayload; + const {recipients, action, locale, question} = JSON.parse(event.body) as RequestPayload; if (!recipients) { return { @@ -64,6 +65,13 @@ const handler: Handler = async (event) => { }; } + if (!question) { + return { + statusCode: 422, + body: 'The question is missing.', + }; + } + if (!action || !["invite", "admin"].includes(action)) { return { statusCode: 422, @@ -94,7 +102,7 @@ const handler: Handler = async (event) => { // from: `${i18next.t("Mieux Voter")} `, from: FROM_EMAIL_ADDRESS || '"Mieux Voter" ', to: Object.keys(recipients), - subject: i18next.t(`email.${action}.subject`), + subject: i18next.t(`email.${action}.subject`, {question}), txt: contents[0], html: contents[1], 'h:Reply-To': REPLY_TO_EMAIL_ADDRESS || 'app@mieuxvoter.fr', diff --git a/services/mail.ts b/services/mail.ts index 3944db3..b0c773f 100644 --- a/services/mail.ts +++ b/services/mail.ts @@ -1,6 +1,6 @@ -import { NextRouter } from 'next/router'; -import { getLocaleShort } from './utils'; -import { availableLanguages } from '@functions/i18next'; +import {NextRouter} from 'next/router'; +import {getLocaleShort} from './utils'; +import {availableLanguages} from '@functions/i18next'; export const sendInviteMails = async ( mails: Array, @@ -41,6 +41,7 @@ export const sendInviteMails = async ( }, body: JSON.stringify({ action: 'invite', + question: name, recipients, locale, }), @@ -70,6 +71,7 @@ export const sendAdminMail = async ( body: JSON.stringify({ action: 'admin', locale, + question: name, recipients: { [mail]: { urlAdmin,