From 44a5be8717d668d3d9fd69f8796f53f46fa1c9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 17 Nov 2023 16:16:34 +0000 Subject: [PATCH] fix: Change `undefined` to `null` in `confirmationEmailSchema` (#2438) * fix: Change undefined to null in confirmationEmailSchema * fix: Don't setup email reminder events if a session is submitted --- api.planx.uk/modules/saveAndReturn/service/utils.ts | 6 +++++- api.planx.uk/modules/sendEmail/index.test.ts | 1 + api.planx.uk/modules/sendEmail/types.ts | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api.planx.uk/modules/saveAndReturn/service/utils.ts b/api.planx.uk/modules/saveAndReturn/service/utils.ts index aa61ee7658..a46968a7b0 100644 --- a/api.planx.uk/modules/saveAndReturn/service/utils.ts +++ b/api.planx.uk/modules/saveAndReturn/service/utils.ts @@ -72,7 +72,8 @@ const sendSingleApplicationEmail = async ({ emailReplyToId: team.notifyPersonalisation.emailReplyToId, }; const firstSave = !session.hasUserSaved; - if (firstSave) await setupEmailEventTriggers(sessionId); + if (firstSave && !session.submittedAt) + await setupEmailEventTriggers(sessionId); return await sendEmail(template, email, config); } catch (error) { throw Error((error as Error).message); @@ -98,6 +99,7 @@ const validateSingleSessionRequest = async ( id data created_at + submitted_at has_user_saved flow { slug @@ -139,6 +141,7 @@ interface SessionDetails { projectType: string; id: string; expiryDate: string; + submittedAt: string | null; } /** @@ -162,6 +165,7 @@ const getSessionDetails = async ( id: session.id, expiryDate: calculateExpiryDate(session.created_at), hasUserSaved: session.has_user_saved, + submittedAt: session.submitted_at, }; }; diff --git a/api.planx.uk/modules/sendEmail/index.test.ts b/api.planx.uk/modules/sendEmail/index.test.ts index 996fa16d35..96debfbfcc 100644 --- a/api.planx.uk/modules/sendEmail/index.test.ts +++ b/api.planx.uk/modules/sendEmail/index.test.ts @@ -186,6 +186,7 @@ describe("Send Email endpoint", () => { payload: { sessionId: "123", email: TEST_EMAIL, + lockedAt: null, }, }; await supertest(app) diff --git a/api.planx.uk/modules/sendEmail/types.ts b/api.planx.uk/modules/sendEmail/types.ts index ae24d85519..4f17cd3a72 100644 --- a/api.planx.uk/modules/sendEmail/types.ts +++ b/api.planx.uk/modules/sendEmail/types.ts @@ -50,7 +50,7 @@ export const confirmationEmailSchema = z.object({ body: z.object({ payload: z.object({ sessionId: z.string(), - lockedAt: z.string().optional(), + lockedAt: z.string().or(z.null()), email: z.string().email(), }), }),