Follow+Notes: Create backend library for grants collaboration management #3201
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
Blocks
Definition of Done
A new library,
packages/server/src/lib/grantsCollaboration
exists and provides an interface for saving and retrieving notes created by users about particular grants.Implementation Details
(grant_notes.grant_id, grant_notes.user_id)
) but may have infinite revisions.grantsCollaboration/notes.js
file and imported/exported by agrantsCollaboration/index.js
file, which will allow for this library to remain well-organized as it is expanded to provided additional features.packages/server/src/lib/grantsCollaboration
which exports the following interface:saveNoteRevision(knex, grantId, userId, text)
knex
argument represents aknex
connection object, e.g. as exported bypackages/server/src/db/index.js
.grant_notes
table already exists for the givengrantId
anduserId
. If a row for this combination does not already exist, a new one must be inserted. In case of an insert, theid
of the newly-inserted row must be retained. Otherwise, theid
of the existing row must be retained.grant_notes.id
value, insert a new row into thegrant_notes_revisions
table with the provided text.null
orundefined
or else the database insert operation(s) will fail.getOrganizationNotesForGrant(knex, grantId, organizationId, { afterRevision, limit = 50 } = {})
grant_notes_revisions.created_at
in descending order (most recent first).afterRevision
argument, the query should be limited to results wheregrant_notes_revisions.id
is greater than that value.LEFT JOIN LATERAL
expression to efficiently limit results to the latest revision of each note. In case it's useful, please refer to the following raw SQL as a demonstration of this pattern:LEFT JOIN LATERAL
, so this will need to be provided as text to a.joinRaw()
call on the chained query object.The text was updated successfully, but these errors were encountered: