From 07580fdccd563e2b8f7e5a9f127fad9b6dfcc45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 17 Nov 2023 11:22:21 +0000 Subject: [PATCH 1/2] fix: Change undefined to null in confirmationEmailSchema --- api.planx.uk/modules/sendEmail/index.test.ts | 1 + api.planx.uk/modules/sendEmail/types.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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(), }), }), From 5b0ad6ff8c90b26c9a8ee3bdeab84ee061a277ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 17 Nov 2023 11:31:06 +0000 Subject: [PATCH 2/2] fix: Don't setup email reminder events if a session is submitted --- api.planx.uk/modules/saveAndReturn/service/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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, }; };