-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grants-collaboration): create follow/unfollow funcs (#3337)
- Loading branch information
Amy Wang
authored
Aug 5, 2024
1 parent
2d5ce66
commit 0f61dab
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
async function followGrant(knex, grantId, userId) { | ||
return knex.transaction(async (trx) => { | ||
try { | ||
await trx('grant_followers').insert({ grant_id: grantId, user_id: userId }); | ||
} catch (err) { | ||
if (err.code === '23505') { // unique constraint violation | ||
await trx.rollback(); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
async function unfollowGrant(knex, grantId, userId) { | ||
await knex('grant_followers') | ||
.where({ grant_id: grantId, user_id: userId }) | ||
.del(); | ||
} | ||
|
||
module.exports = { followGrant, unfollowGrant }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const { saveNoteRevision, getOrganizationNotesForGrant } = require('./notes'); | ||
const { followGrant, unfollowGrant } = require('./followers'); | ||
|
||
module.exports = { | ||
saveNoteRevision, getOrganizationNotesForGrant, | ||
saveNoteRevision, getOrganizationNotesForGrant, followGrant, unfollowGrant, | ||
}; |