From 08f9c5bd9156517eaaa464291977720f61541607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Mon, 18 Nov 2024 10:38:08 +0000 Subject: [PATCH] fix: Only trigger `email_user_submission_confirmation` event once per session (#3967) --- .../modules/saveAndReturn/service/utils.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/api.planx.uk/modules/saveAndReturn/service/utils.ts b/api.planx.uk/modules/saveAndReturn/service/utils.ts index c5d1c20a8a..3f985bd33a 100644 --- a/api.planx.uk/modules/saveAndReturn/service/utils.ts +++ b/api.planx.uk/modules/saveAndReturn/service/utils.ts @@ -217,17 +217,26 @@ const softDeleteSession = async (sessionId: string) => { /** * Mark a lowcal_session record as submitted + * Sends confirmation emails via Hasura event trigger "email_user_submission_confirmation" * Sessions older than 6 months cleaned up nightly by cron job sanitise_application_data on Hasura */ const markSessionAsSubmitted = async (sessionId: string) => { try { const mutation = gql` mutation MarkSessionAsSubmitted($sessionId: uuid!) { - update_lowcal_sessions_by_pk( - pk_columns: { id: $sessionId } + update_lowcal_sessions( + where: { + _and: { + id: { _eq: $sessionId } + # Only trigger email on first submission + submitted_at: { _is_null: true } + } + } _set: { submitted_at: "now()" } ) { - id + returning { + id + } } } `;