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

Follow+Notes: Expose ability to retrieve grant followers via Finder API #3399

Open
Tracked by #2960
TylerHendrickson opened this issue Aug 16, 2024 · 0 comments
Open
Tracked by #2960
Assignees
Labels
collaboration Grant Finder Issues related to the Grant Finder javascript Pull requests that update Javascript code

Comments

@TylerHendrickson
Copy link
Member

TylerHendrickson commented Aug 16, 2024

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 users retrieve followers (within the same tenant/organization) of a particular grant.

Implementation Details

  • In packages/server/src/lib/grantsCollaboration/followers.js, update the exported interface with the following functions:
    • getFollowersForGrant(knex, grantId, organizationId, { beforeFollow, limit = 50 })
      • Performs a query for grant followers pertaining to the identified grant and organization
      • Results should be ordered by grant_followers.created_at in descending order (most recent first).
      • The knex argument represents a knex connection object, e.g. as implemented by the existing followGrant() function.
      • If a non-null/-undefined value is provided for the beforeFollow argument, the main query should be limited to results where grant_followers.id is less than that value.
      • This function should return an object that matches the following structure:
        {
          followers: [{
            id: grant_followers.id,
            createdAt: grant_followers.created_at,
            grant: { id: grant_followers.grant_id },
            user: {
              id: grant_followers.user_id,
              name: users.name,
              email: users.email,
              team: {
                id: users.agency_id,
                name: agencies.name,
              },
              organization: {
                id: users.tenant_id,
                name: tenants.name,
              },
            }
          }],
          pagination: {
            from: followers.length > 0 ? followers[followers.length - 1].id : beforeFollow,
          },
        }
        • Note that followersTotalCount is the result of the count query
  • In packages/server/src/lib/grantsCollaboration/index.js, import/export the getFollowersForGrant() function exported from packages/server/src/lib/grantsCollaboration/followers.js
  • In packages/server/src/routes/grants.js, define a new GET /:grantId/followers API route handler as follows:
    • Requires authentication.
    • Calls getFollowersForGrant() from packages/server/src/lib/grantsCollaboration with the grant ID and organization ID from the request.
      • The grantId call argument should be provided by the request path parameters.
      • The organizationId call argument should be the requesting user's tenant_id attribute (i.e. req.session.user.tenant_id).
    • If a ?paginateFrom query parameter value is provided in the request, that value should be provided as the beforeFollow argument in the call to getFollowersForGrant().
    • If a ?limit query parameter value is provided in the request, that value (as a parsed integer) should be provided as the limit argument in the call to getFollowersForGrant(). Additionally, this value must pass the following validation checks (or else respond with a 400 Bad Request status):
      • Can be successfully parsed as an integer
      • Parsed integer value must be greater than or equal to 1
      • Parsed integer value must not exceed 100
    • Following a successful call to getFollowersForGrant(), provides the function's return value as a JSON-serialized response.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collaboration Grant Finder Issues related to the Grant Finder javascript Pull requests that update Javascript code
Projects
Status: 🚢 Completed
Development

No branches or pull requests

2 participants