From 016032a27c2d0ff6bf8da3d434f810011ed4c0e1 Mon Sep 17 00:00:00 2001 From: Job Dufitumukiza Date: Sun, 6 Oct 2024 20:50:53 +0300 Subject: [PATCH 1/3] Add API route for marking a post as instructor-approved - Added a new PUT route /:pid/approve to handle post approval. - Integrated middleware to check admin privileges. - Implemented controller logic to mark posts as approved by an instructor. --- src/routes/write/posts.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/routes/write/posts.js b/src/routes/write/posts.js index e573bbb9b0..33fda85a2a 100644 --- a/src/routes/write/posts.js +++ b/src/routes/write/posts.js @@ -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); From aa381ee770ec9a6d07e488f5f94c5908c4f281b3 Mon Sep 17 00:00:00 2001 From: Job Dufitumukiza Date: Sun, 6 Oct 2024 21:07:48 +0300 Subject: [PATCH 2/3] Add approve function to Posts controller - Implemented the approve function to handle post approval logic. - The function marks a post as approved by an instructor. - Returns a success message upon successful approval. - Handles errors and returns an appropriate error message if approval fails. --- src/controllers/write/posts.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/controllers/write/posts.js b/src/controllers/write/posts.js index 1dc8cf6800..3eab7f8f05 100644 --- a/src/controllers/write/posts.js +++ b/src/controllers/write/posts.js @@ -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); + res.status(200).json({ message: 'Post approved successfully' }); + } catch (error) { + res.status(500).json({ error: 'An error occurred while approving the post' }); + } +}; From e06ea15ae4601c9c8ded8e0bb92cc06ff6a3256b Mon Sep 17 00:00:00 2001 From: Job Dufitumukiza Date: Mon, 7 Oct 2024 17:17:25 +0300 Subject: [PATCH 3/3] fixed lint test identation issues in the src/controllers/write/post.js. The issue was about identation syntax issues from line 185 but there one issue i can not fix since there is dependence so i am waiting for my teammate to implement his part so that i can pass lint test --- src/controllers/write/posts.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/controllers/write/posts.js b/src/controllers/write/posts.js index 3eab7f8f05..f6564b2da6 100644 --- a/src/controllers/write/posts.js +++ b/src/controllers/write/posts.js @@ -181,12 +181,12 @@ Posts.getReplies = async (req, res) => { }; // 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); - res.status(200).json({ message: 'Post approved successfully' }); - } catch (error) { - res.status(500).json({ error: 'An error occurred while approving the post' }); - } + try { + const { pid } = req.params; + // Assuming you have a function to mark the post as approved + await markPostAsApproved(pid, req.user.id); + res.status(200).json({ message: 'Post approved successfully' }); + } catch (error) { + res.status(500).json({ error: 'An error occurred while approving the post' }); + } };