Skip to content

Commit

Permalink
Show queue position in confirmation email
Browse files Browse the repository at this point in the history
  • Loading branch information
PurkkaKoodari committed Sep 6, 2024
1 parent ccf143e commit d582005
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
8 changes: 6 additions & 2 deletions packages/ilmomasiina-backend/emails/en/confirmation.pug
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions packages/ilmomasiina-backend/emails/fi/confirmation.pug
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/ilmomasiina-backend/src/mail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ConfirmationMailParams {
label: string;
answer: string;
}[];
queuePosition: number | null;
edited: boolean;
date: string | null;
event: Event;
Expand Down
6 changes: 3 additions & 3 deletions packages/ilmomasiina-backend/src/mail/signupConfirmation.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default async function updateSignup(
request: FastifyRequest<{ Params: SignupPathParams; Body: SignupUpdateBody }>,
reply: FastifyReply,
): Promise<SignupUpdateResponse> {
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,
});
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d582005

Please sign in to comment.