From 846b858cf99fa9e55b20c98e20ca147009932dee Mon Sep 17 00:00:00 2001 From: Aj_shadow <105531661+Avijit-roy@users.noreply.github.com> Date: Tue, 6 Jan 2026 20:27:24 +0530 Subject: [PATCH] Update user.js Rearrange user routes to improve readability and clarity. improved the organization and usability of the routes: Routes were categorized according to the level of authentication (public vs. protected). For cleaner syntax, the `.route()` chaining was replaced with direct method calls; imports were reformatted to span multiple lines for easier reading. Route groups were visually separated with comments. In addition to making it much clearer which endpoints require authentication and which do not, this also makes it simpler to scan the file when searching for a particular route. --- routes/user.js | 69 +++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/routes/user.js b/routes/user.js index f0d1e5f..d196b4b 100644 --- a/routes/user.js +++ b/routes/user.js @@ -1,31 +1,48 @@ -const express = require("express"); -const { getUser, postStory, editYourDetail, changePassword, requestOTP, feed, sendNotice, togglefollowPeople, togglefollowTopic, searchUser, getSuggestedStory, togglesaveStory, removeFromReadingList, addToReadingList, getUserData, getFollowingStories, getSuggestedUser, getsuggestedTopic } = require("../controllers/user"); - +const express = require('express'); const router = express.Router(); +const { Verify, VerifyWithoutThrowingError } = require('../middleware/auth'); -const { Verify, VerifyWithoutThrowingError } = require("../middleware/auth"); - - -router.route("/addstory").post(Verify,postStory); -router.route("/").put(Verify,editYourDetail); -router.route("/changepassword").post(Verify,changePassword); -router.route("/requestOTP").get(Verify,requestOTP); -router.route("/").post(VerifyWithoutThrowingError,feed); -router.route("/getnotice").get(Verify,sendNotice); -router.route("/togglefollowpeople").post(Verify,togglefollowPeople); -router.route("/togglefollowtopic").post(Verify,togglefollowTopic); -router.route("/search").post(VerifyWithoutThrowingError,searchUser); +const { + getUser, + postStory, + editYourDetail, + changePassword, + requestOTP, + feed, + sendNotice, + togglefollowPeople, + togglefollowTopic, + searchUser, + getSuggestedStory, + togglesaveStory, + removeFromReadingList, + addToReadingList, + getUserData, + getFollowingStories, + getSuggestedUser, + getsuggestedTopic +} = require('../controllers/user'); -router.route("/getuserdata/:uid").get(VerifyWithoutThrowingError,getUserData); -router.route("/getfollowingstory").get(VerifyWithoutThrowingError,getFollowingStories); -router.route("/getsuggestedstory").get(VerifyWithoutThrowingError,getSuggestedStory); -router.route("/getsuggesteduser").get(VerifyWithoutThrowingError,getSuggestedUser); -router.route("/getsuggestedtopic").get(VerifyWithoutThrowingError,getsuggestedTopic); -router.route("/addtoreadinglist/:sid").get(Verify,addToReadingList); -router.route("/togglesavestory/:sid").get(Verify,togglesaveStory); -router.route("/removefromreadinglist/:sid").get(Verify,removeFromReadingList); -router.route("/:uid").get(VerifyWithoutThrowingError,getUser); - +// Public routes (no auth required) +router.get('/search', VerifyWithoutThrowingError, searchUser); +router.get('/getuserdata/:uid', VerifyWithoutThrowingError, getUserData); +router.get('/getfollowingstory', VerifyWithoutThrowingError, getFollowingStories); +router.get('/getsuggestedstory', VerifyWithoutThrowingError, getSuggestedStory); +router.get('/getsuggesteduser', VerifyWithoutThrowingError, getSuggestedUser); +router.get('/getsuggestedtopic', VerifyWithoutThrowingError, getsuggestedTopic); +router.get('/:uid', VerifyWithoutThrowingError, getUser); +router.post('/', VerifyWithoutThrowingError, feed); +// Protected routes (auth required) +router.post('/addstory', Verify, postStory); +router.put('/', Verify, editYourDetail); +router.post('/changepassword', Verify, changePassword); +router.get('/requestOTP', Verify, requestOTP); +router.get('/getnotice', Verify, sendNotice); +router.post('/togglefollowpeople', Verify, togglefollowPeople); +router.post('/togglefollowtopic', Verify, togglefollowTopic); +router.get('/addtoreadinglist/:sid', Verify, addToReadingList); +router.get('/togglesavestory/:sid', Verify, togglesaveStory); +router.get('/removefromreadinglist/:sid', Verify, removeFromReadingList); -module.exports = router; \ No newline at end of file +module.exports = router;