diff --git a/packages/ilmomasiina-backend/emails/en/confirmation.pug b/packages/ilmomasiina-backend/emails/en/confirmation.pug index 26fd51ff..24915db0 100644 --- a/packages/ilmomasiina-backend/emails/en/confirmation.pug +++ b/packages/ilmomasiina-backend/emails/en/confirmation.pug @@ -1,8 +1,12 @@ extends ../layout.pug block mainContent - div.content-block - p.bodyText #{event.verificationEmail} + if event.verificationEmail + div.content-block + p.bodyText #{event.verificationEmail} + if queuePosition + div.content-block + p.bodyText #[strong You are in the queue in position #{queuePosition}.] If you get accepted from the queue, you will be notified by email. div.content-block p.bodyText Event details: ul diff --git a/packages/ilmomasiina-backend/emails/fi/confirmation.pug b/packages/ilmomasiina-backend/emails/fi/confirmation.pug index 198bb861..e269457d 100644 --- a/packages/ilmomasiina-backend/emails/fi/confirmation.pug +++ b/packages/ilmomasiina-backend/emails/fi/confirmation.pug @@ -1,8 +1,12 @@ extends ../layout.pug block mainContent - div.content-block - p.bodyText #{event.verificationEmail} + if event.verificationEmail + div.content-block + p.bodyText #{event.verificationEmail} + if queuePosition + div.content-block + p.bodyText #[strong Olet jonossa sijalla #{queuePosition}.] Jos saat paikan jonosta, sinulle lähetetään ilmoitus sähköpostitse. div.content-block p.bodyText Tapahtuman tiedot: ul diff --git a/packages/ilmomasiina-backend/src/mail/index.ts b/packages/ilmomasiina-backend/src/mail/index.ts index 93deab37..35cee37a 100644 --- a/packages/ilmomasiina-backend/src/mail/index.ts +++ b/packages/ilmomasiina-backend/src/mail/index.ts @@ -16,6 +16,7 @@ export interface ConfirmationMailParams { label: string; answer: string; }[]; + queuePosition: number | null; edited: boolean; date: string | null; event: Event; diff --git a/packages/ilmomasiina-backend/src/mail/signupConfirmation.ts b/packages/ilmomasiina-backend/src/mail/signupConfirmation.ts index 58c214b8..6efb35ad 100644 --- a/packages/ilmomasiina-backend/src/mail/signupConfirmation.ts +++ b/packages/ilmomasiina-backend/src/mail/signupConfirmation.ts @@ -1,12 +1,13 @@ import moment from "moment-timezone"; +import { SignupStatus } from "@tietokilta/ilmomasiina-models"; import config from "../config"; import i18n from "../i18n"; import { Signup } from "../models/signup"; import { generateToken } from "../routes/signups/editTokens"; import EmailService from "."; -export default async function sendSignupConfirmationMail(signup: Signup) { +export default async function sendSignupConfirmationMail(signup: Signup, edited: boolean) { if (signup.email === null) return; const lng = signup.language ?? undefined; @@ -28,8 +29,6 @@ export default async function sendSignupConfirmationMail(signup: Signup) { answer: Array.isArray(answer!.answer) ? answer!.answer.join(", ") : answer!.answer, })); - const edited = answers.some((answer) => answer.createdAt.getTime() !== answer.updatedAt.getTime()); - const dateFormat = i18n.t("dateFormat.general", { lng }); const date = event.date && moment(event.date).tz(config.timezone).format(dateFormat); @@ -44,6 +43,7 @@ export default async function sendSignupConfirmationMail(signup: Signup) { email: signup.email, quota: quota.title, answers: questionFields, + queuePosition: signup.status === SignupStatus.IN_QUEUE ? signup.position : null, edited, date, event, diff --git a/packages/ilmomasiina-backend/src/routes/signups/updateSignup.ts b/packages/ilmomasiina-backend/src/routes/signups/updateSignup.ts index fdc9689f..4b39eadd 100644 --- a/packages/ilmomasiina-backend/src/routes/signups/updateSignup.ts +++ b/packages/ilmomasiina-backend/src/routes/signups/updateSignup.ts @@ -18,10 +18,10 @@ export default async function updateSignup( request: FastifyRequest<{ Params: SignupPathParams; Body: SignupUpdateBody }>, reply: FastifyReply, ): Promise { - const updatedSignup = await getSequelize().transaction(async (transaction) => { + const { updatedSignup, edited } = await getSequelize().transaction(async (transaction) => { // Retrieve event data and lock the row for editing const signup = await Signup.scope("active").findByPk(request.params.id, { - attributes: ["id", "quotaId", "confirmedAt", "firstName", "lastName", "email", "language"], + attributes: ["id", "quotaId", "confirmedAt", "firstName", "lastName", "email", "language", "status", "position"], transaction, lock: Transaction.LOCK.UPDATE, }); @@ -156,11 +156,11 @@ export default async function updateSignup( transaction, }); - return signup; + return { updatedSignup: signup, edited: !notConfirmedYet }; }); // Send the confirmation email - sendSignupConfirmationMail(updatedSignup); + sendSignupConfirmationMail(updatedSignup, edited); // Return data reply.status(200);