The library at packages/server/src/lib/grantsCollaboration provides new exported functions for adding, removing, and retrieving followers of grants.
Implementation Details
Create a knex migration that defines a new grant_followers table with the following schema:
Columns:
id: serial, not null, primary key
grant_id: text, not null, foreign key to grants.grant_id
user_id: int, not null, foreign key to users.id
created_at: timestamp with time zone, not null, default now()
Unique index idx_grant_id_user_id on columns (grant_id, user_id)
Add the following functions to the exported interface of the packages/server/src/lib/grantsCollaboration library:
followGrant(knex, grantId, userId) (void)
This function should insert a new row into the grant_followers table to record that the identified user is now following the identified grant.
The knex argument represents a knex connection object, e.g. as exported by packages/server/src/db/index.js.
Unique constraint violations that may occur upon insert (i.e. because the user is already following the grant) should be handled in such a way that any database transaction associated with the provided knex object may proceed. Therefore, this function should begin a new (sub-)transaction before insert, roll back the transaction on unique constraint violation, and commit the transaction following a successful insert.
unfollowGrant(knex, grantId, userId) (void)
This function should delete the row pertaining to the given user/grant combination from the grant_followers table.
Note that while these functions should be exported by the grantsCollaboration library, they should be defined in grantsCollaboration/followers.js and imported/exported in grantsCollaboration/index.js.
Subtask of [STORY]: Update 'Status' to 'Follow + Note' feature #2960
Blocked by
3201
Blocks
3204
3206
3207
Definition of Done
The library at
packages/server/src/lib/grantsCollaboration
provides new exported functions for adding, removing, and retrieving followers of grants.Implementation Details
grant_followers
table with the following schema:id
: serial, not null, primary keygrant_id
: text, not null, foreign key togrants.grant_id
user_id
: int, not null, foreign key tousers.id
created_at
: timestamp with time zone, not null, defaultnow()
idx_grant_id_user_id
on columns(grant_id, user_id)
packages/server/src/lib/grantsCollaboration
library:followGrant(knex, grantId, userId)
(void)grant_followers
table to record that the identified user is now following the identified grant.knex
argument represents aknex
connection object, e.g. as exported bypackages/server/src/db/index.js
.knex
object may proceed. Therefore, this function should begin a new (sub-)transaction before insert, roll back the transaction on unique constraint violation, and commit the transaction following a successful insert.unfollowGrant(knex, grantId, userId)
(void)grant_followers
table.grantsCollaboration
library, they should be defined ingrantsCollaboration/followers.js
and imported/exported ingrantsCollaboration/index.js
.