Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only trigger email_user_submission_confirmation event once per session #3967

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading