Skip to content

Commit

Permalink
fix: Only trigger email_user_submission_confirmation event once per…
Browse files Browse the repository at this point in the history
… session (#3967)
  • Loading branch information
DafyddLlyr authored Nov 18, 2024
1 parent 84f0afb commit 08f9c5b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions api.planx.uk/modules/saveAndReturn/service/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
`;
Expand Down

0 comments on commit 08f9c5b

Please sign in to comment.