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: Don't overwrite req with parsedReq #2354

Merged
merged 2 commits into from
Nov 2, 2023
Merged

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Oct 31, 2023

What's the problem?

A "reminder" email failed this morning - the reason for this was that the required "email" field was missing from the event sent to Hasura.

What caused this?

This field was missed when typing the schema for this endpoint. This happened as the routeSendEmailRequest() function is not yet typed - meaning the variable was missed.

What's the solution?

  • Add "email" to schema
  • Add test cases
  • Also, don't overwrite req with parsedReq - this change means that non-updated endpoints shouldn't fail as the original req object is not touched. I'm now writing to res.locals (docs) which is a nice solution to the issue I was talking about in a previous dev call. We can now coerce types as part of validation in the middleware, and not break existing endpoints - this feels like a solid solution here.

Next steps...

I think it's pretty likely that multiple reminder and expiry events setup since this change was made are affected by this problem of a missing email field. These events should be identifiable from the Hasura hdb_catalog tables, and we could then append emails to them. I'll update this thread as I troubleshoot this one.

This might also point towards considering a cron job for these events as an alternative to manage reminder and expiry events. Something to consider!

@DafyddLlyr DafyddLlyr changed the title fix: Don't overwrite req with parsedReq fix: Don't overwrite req with parsedReq Oct 31, 2023
@github-actions
Copy link

github-actions bot commented Oct 31, 2023

Removed vultr server and associated DNS entries

@DafyddLlyr DafyddLlyr force-pushed the dp/reminder-email-variables branch from a117c66 to b155663 Compare October 31, 2023 11:21
@DafyddLlyr DafyddLlyr requested a review from a team October 31, 2023 11:30
@DafyddLlyr DafyddLlyr marked this pull request as ready for review October 31, 2023 11:30
@DafyddLlyr
Copy link
Contributor Author

DafyddLlyr commented Oct 31, 2023

Right, I've now got some SQL I'm happy with which is tested on staging and locally.

We can run this manually on production once this fix is merged (and the SQL is cross-checked please...!).

Events without an email can be found with this query -

SELECT
  *
FROM
  hdb_catalog.hdb_scheduled_events
WHERE
  webhook_conf::TEXT ILIKE '%expiry%'
  AND status = 'scheduled'
  AND payload->'email' IS NULL;

Records can be updated with -

UPDATE
  hdb_catalog.hdb_scheduled_events
SET
  payload = jsonb_set(
    payload::JSONB,
    '{email}',
    ('"' || public.lowcal_sessions.email || '"')::JSONB
  )
FROM
  public.lowcal_sessions
WHERE
  webhook_conf::TEXT ILIKE '%expiry%'
  AND status = 'scheduled'
  AND payload->'email' IS NULL
  AND hdb_scheduled_events.payload->>'sessionId' = public.lowcal_sessions.id::TEXT;

%expiry% and %reminder% would both need to be run - I guess we could combine them into one query but I'd favour a step by step approach juuust to be safe.

Copy link
Contributor

@Mike-Heneghan Mike-Heneghan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@@ -16,7 +16,7 @@ import { SanitiseApplicationData } from "./service/sanitiseApplicationData/types
import { sanitiseApplicationData } from "./service/sanitiseApplicationData";

export const sendSlackNotificationController: SendSlackNotification = async (
req,
_req,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

Am I right in saying _req is still being passed in despite not being used directly as down the chain it is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, _req is always passed in, but no longer used in this instance. We're using the underscore prefix to indicate that this is an unused variable - there's a linting rule set up for this in .eslintrc under @typescript-eslint/no-unused-vars

@Mike-Heneghan
Copy link
Contributor

Right, I've now got some SQL I'm happy with which is tested on staging and locally.

We can run this manually on production once this fix is merged (and the SQL is cross-checked please...!).

Events without an email can be found with this query -

SELECT
  *
FROM
  hdb_catalog.hdb_scheduled_events
WHERE
  webhook_conf::TEXT ILIKE '%expiry%'
  AND status = 'scheduled'
  AND payload->'email' IS NULL;

Records can be updated with -

UPDATE
  hdb_catalog.hdb_scheduled_events
SET
  payload = jsonb_set(
    payload::JSONB,
    '{email}',
    ('"' || public.lowcal_sessions.email || '"')::JSONB
  )
FROM
  public.lowcal_sessions
WHERE
  webhook_conf::TEXT ILIKE '%expiry%'
  AND status = 'scheduled'
  AND payload->'email' IS NULL
  AND hdb_scheduled_events.payload->>'sessionId' = public.lowcal_sessions.id::TEXT;

%expiry% and %reminder% would both need to be run - I guess we could combine them into one query but I'd favour a step by step approach juuust to be safe.

This looks as if it would do what you're intending as far as I can see. Can you remind me where you'd actually run this? Also, I'm happy to jump on a call to go through this 👍

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes & proposed SQL look good to me here 👍

One question about the SQL - the email param is only expected in payloads for session reminders and expiry events, right? Not, payment_ reminder & expiry too? Just double checking we're catching everything expected with this update.

@DafyddLlyr
Copy link
Contributor Author

One question about the SQL - the email param is only expected in payloads for session reminders and expiry events, right? Not, payment_ reminder & expiry too? Just double checking we're catching everything expected with this update.

This is a good question! I've double checked this and invite to pay emails just need a paymentRequestId and nothing else 👌

template: |-
{
"createdAt": {{$body.event.data.new.created_at}},
"payload": {
"paymentRequestId": {{$body.event.data.new.id}}
}
}
url: '{{$base_url}}/webhooks/hasura/create-payment-invitation-events'

@DafyddLlyr
Copy link
Contributor Author

I'm going to go ahead and merge this - I'll run the SQL once this has got to production and will then update this PR with a paper trail confirming it's been done successfully.

@DafyddLlyr DafyddLlyr merged commit cde4cd5 into main Nov 2, 2023
10 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/reminder-email-variables branch November 2, 2023 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants