From 3a6ebb5b38f3c2f563a549f55be410f0233086a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 15 Nov 2024 15:02:34 +0000 Subject: [PATCH] fix: Only trigger `email_user_submission_confirmation` event once per session --- .../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 + } } } `;