Follow+Notes: Retrieve note(s) for grant by a specific user via Finder API #3426
Labels
collaboration
Grant Finder
Issues related to the Grant Finder
javascript
Pull requests that update Javascript code
Subtask of [STORY]: Update 'Status' to 'Follow + Note' feature #2960
Blocked by
N/A
Blocks
Definition of Done
A new API route exists that allows retrieval of the latest revision for each note pertaining to a specific user and grant.
Implementation Details
packages/server/src/lib/grantsCollaboration/notes.js
, update the exported interface with the following functions:getOrganizationNotesForGrantByUser(knex, organizationId, userId, grantId, { afterRevision, limit = 50 } = {})
grant_notes_revisions.created_at
in descending order (most recent first).getOrganizationNotesForGrant()
function togetCurrentNoteRevisions()
and update it's argument signature to(knex, { grantId, organizationId, userId } = {}, { afterRevision, limit = 50 } = {})
.getCurrentNotesRevisions()
function so that theWHERE
filters of the query pertaining togrant_notes.grant_id = :grantId
andgrant_notes.user_id = :userId
are conditional and only applied whengrantId
anduserId
are not null/undefined
. In other words, we want to make the behavior of limiting query results to those pertaining to a specific user and/or grant optional.getOrganizationNotesForGrantByUser()
function as a simple wrapper that callsgetCurrentNotesRevisions()
and returns the return value from that internal call, e.g.packages/server/src/lib/grantsCollaboration/notes.js
module.getOrganizationNotesForGrant(knex, grantId, organizationId, { afterRevision, limit = 50 } = {})
function (which implements the same original call signature) as another simple wrapper forgetCurrentNoteRevisions()
, e.g.packages/server/src/lib/grantsCollaboration/index.js
, import/export thegetOrganizationNotesForGrantByUser()
function exported frompackages/server/src/lib/grantsCollaboration/notes.js
packages/server/src/routes/grants.js
, define a newGET /:grantId/notes/user/:userId
API route handler as follows:getOrganizationNotesForGrantByUser()
frompackages/server/src/lib/grantsCollaboration
to retrieve a (paginated) result set of notes pertaining to the grant, organization, and user identified in the request.grantId
anduserId
call arguments togetOrganizationNotesForGrantByUser()
should all be derived from the corresponding request path parameter (req.params
) values.organizationId
call argument togetOrganizationNotesForGrantByUser()
should be thetenant_id
of the user provided by the request session (req.session.user.tenant_id
)?paginateFrom
query parameter value is provided in the request, that value should be provided as theafterRevision
argument in the call togetOrganizationNotesForGrantByUser()
.?limit
query parameter value is provided in the request, that value (as a parsed integer) should be provided as thelimit
argument in the call togetOrganizationNotesForGrantByUser()
. Additionally, this value must pass the following validation checks (or else respond with a400 Bad Request
status):getOrganizationNotesForGrantByUser()
, provides the function's return value as a JSON-serialized response.The text was updated successfully, but these errors were encountered: