Skip to content

Commit

Permalink
feat(grants-collaboration): expose unfollow for grant (#3396)
Browse files Browse the repository at this point in the history
* add route

* add test

* update signature doc

* remove unused

* remove use of db module
  • Loading branch information
greg-adams authored Aug 22, 2024
1 parent 7000795 commit 323058e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/server/__tests__/api/grants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,23 @@ HHS-2021-IHS-TPI-0001,Community Health Aide Program: Tribal Planning &`;
});
});

context('DELETE api/grants/:grantId/follow', () => {
const GRANT_ID = '335255';

beforeEach(async () => {
await knex('grant_followers').insert({ grant_id: GRANT_ID, user_id: staffUser.id });
});

it('deletes follower record for request user', async () => {
const resp = await fetchApi(`/grants/${GRANT_ID}/follow`, agencies.own, {
...fetchOptions.staff,
method: 'delete',
});

expect(resp.statusText).to.equal('OK');
});
});

context('GET api/grants/:grantId/notes', () => {
const GRANT_ID = '335255';

Expand Down
12 changes: 11 additions & 1 deletion packages/server/src/routes/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const db = require('../db');
const email = require('../lib/email');
const { requireUser, isUserAuthorized } = require('../lib/access-helpers');
const knex = require('../db/connection');
const { saveNoteRevision, followGrant, getOrganizationNotesForGrant } = require('../lib/grantsCollaboration');
const {
saveNoteRevision, followGrant, unfollowGrant, getOrganizationNotesForGrant,
} = require('../lib/grantsCollaboration');

const router = express.Router({ mergeParams: true });

Expand Down Expand Up @@ -424,6 +426,14 @@ router.delete('/:grantId/interested/:agencyId', requireUser, async (req, res) =>
res.json({});
});

router.delete('/:grantId/follow', requireUser, async (req, res) => {
const { user } = req.session;
const { grantId } = req.params;

await unfollowGrant(knex, grantId, user.id);
res.json({});
});

router.get('/:grantId/notes', requireUser, async (req, res) => {
const { grantId } = req.params;
const { user } = req.session;
Expand Down

0 comments on commit 323058e

Please sign in to comment.