Skip to content

Commit

Permalink
Merge pull request #43 from jdufitum/task-3-api-endpoint
Browse files Browse the repository at this point in the history
Create API Endpoint for Approving Posts with Admin Privileges
  • Loading branch information
jdufitum authored Oct 20, 2024
2 parents e3c0ea1 + e06ea15 commit 98ff83b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/controllers/write/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ Posts.getReplies = async (req, res) => {

helpers.formatApiResponse(200, res, { replies });
};
// Add the approve function
Posts.approve = async (req, res) => {
try {
const { pid } = req.params;
// Assuming you have a function to mark the post as approved
await markPostAsApproved(pid, req.user.id);

Check failure on line 187 in src/controllers/write/posts.js

View workflow job for this annotation

GitHub Actions / test

'markPostAsApproved' is not defined
res.status(200).json({ message: 'Post approved successfully' });
} catch (error) {
res.status(500).json({ error: 'An error occurred while approving the post' });
}
};
2 changes: 2 additions & 0 deletions src/routes/write/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module.exports = function () {
setupApiRoute(router, 'delete', '/:pid/diffs/:timestamp', middlewares, controllers.write.posts.deleteDiff);

setupApiRoute(router, 'get', '/:pid/replies', [middleware.assert.post], controllers.write.posts.getReplies);
// Add the new route for marking a post as "instructor-approved"
setupApiRoute(router, 'put', '/:pid/approve', [...middlewares, middleware.admin.checkPrivileges], controllers.write.posts.approve);

// Shorthand route to access post routes by topic index
router.all('/+byIndex/:index*?', [middleware.checkRequired.bind(null, ['tid'])], controllers.write.posts.redirectByIndex);
Expand Down

0 comments on commit 98ff83b

Please sign in to comment.