-
Notifications
You must be signed in to change notification settings - Fork 13
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
chore: Replace update with simple delete for removeDeliveryOption #4825
base: main
Are you sure you want to change the base?
Conversation
🧪 Review environmenthttps://itcmttfywsep45oqstddwchqja0ujbmq.lambda-url.ca-central-1.on.aws/ |
lib/templates.ts
Outdated
try { | ||
await authorization.canEditForm(ability, formID); | ||
|
||
const updatedTemplate = await prisma.template | ||
.update({ | ||
await prisma.deliveryOption |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming that we're allowing the removeDeliveryOption
to run on published forms?
The initial reason to use the prisma.template.update()
was the ability to check if the form was published in the unique where:{ }
before deleting the delivery option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take this back to draft, as there seems to be another bug introduced.
But yeah maybe this will just have to be two queries either way:
Check to make sure it's not published, then delete.
OR
Check to see if there is a DeliveryOption and use the update syntax.
The update syntax fails if there was no DeliveryOption set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also catch that specific error in the prisma chain and ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to throw the same error in both cases.
Template with a DeliveryOption and published = true : P2025
And
Template with no DeliveryOption and published = false : P2025
...doesn't make a whole lot of sense as it says "No 'DeliveryOption' record was found ..." in both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a commit with the split check, then delete.
I couldn't get it to work with just the update call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want it to fail silently do we even need to return a descriptive error if the template is already published?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words shouldn't the client side be verifying if the template is already published before trying to make the action call? And if someone tries to hit the action endpoint directly it just returns a generic error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the "live api key version" --- there is code that does the published check.
... depends on where we calling the code from.
Part of this was looking to ensure the server is cleaned up when saving to "the vault".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that said looks like Dave already made some further edits and checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this solution for now. Ideally when we go back to refactoring the templates lib we can see if we can reduce the number of calls to the db.
For example, one of the reasons we have to check externally of the update
function is to return a specific error. Quickly scanning the code-base I see that the TemplateAlreadyPublishedError
and TemplateNotFound
errors are generated in a few places but are never consumed or checked against. So the question becomes do we need to actually throw these custom errors?
Summary | Résumé
removeDeliveryOption was attempting to use a prisma.update to remove the deliveryOption record when changing to API mode. This was not working as expected, and was throwing an incorrect TemplateAlreadyPublishedError.
Modified to:
isPublished
check and throw exception as published templates cannot be changed