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

feat(grants-collaboration): expose unfollow for grant #3396

Merged
merged 12 commits into from
Aug 22, 2024
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
Loading