Open ClaireValdivia opened 1 month ago
@as1729 Personally, I found the API design here unexpected, which threw me off the case a bit this morning. Specifically, I would normally expect to find an endpoint like /:grantId/assign/agencies
to behave something like this:
GET
: returns the list of assigned agencies for the grant (current behavior)POST
: expects a single agency_id
to add to the list of assigned agencies (NEW endpoint)PUT
: expects an agency_ids
array and resets the list of assigned agencies to the supplied list (existing endpoint, but CHANGED behavior — the current endpoint effectively does a set union between the existing assignments and the provided agency_ids
, which feels like unexpected behavior)DELETE
: expects a single agency_id
to remove from the list of assigned agencies (current behavior)And fwiw, I don't know of any good current use cases for the PUT behavior above, so I would fully remove it. Instead, when a user assigns a grant, the frontend should hit the POST endpoint described above with just the single added agency ID. Then we can easily have the server trigger emails just for that given agency ID as part of the route handler for that endpoint.
So to summarize, I would propose a third implementation path:
POST /:grantId/assign/agencies
endpoint that expects a single agency ID, assigns it, and triggers emails just for that agencyWhat do you think?
This is definitely a cleaner implementation rather than building on an already confusing existing api. Let's go with your approach. Thank you!
This is working as expected in staging! Assigned a grant to two teams, and users only received the notification when assigned to their team.
Why is this issue important?
Assignment notifications are not sending correctly and will be confusing to users
Current State
Steps to recreate: Two users from two different teams, both have notifications enabled - one belongs to team USDR and one belongs to team Claire Test.
Expected State
A user will only receive a notification when their team is assigned, not when another team is assigned
Implementation Plan
The issue happens because when the front-end makes a request to the backend to assign agencies, it does not explicitly provide which agencies were just added.
There could be two ways to solve this problem:
Update the front-end to only send the
agencyIds
that were added to the /assign/agencies endpoint.Update how the backend interprets the results when inserting records in the
grants_assigned_agencies
table. https://github.com/usdigitalresponse/usdr-gost/blob/main/packages/server/src/routes/grants.js#L362First update the return value of the
assignGrantsToAgencies
function.Next change what value is passed into
sendGrantAssignedEmails
now that the return value of the above function has changed:Relevant Code Snippets
No response