From c1b7e1c3e85a03c6e7fefb1537bd35bf88ce2efd Mon Sep 17 00:00:00 2001 From: Jainiksha patel Date: Sun, 14 Jun 2026 16:05:54 +0530 Subject: [PATCH 1/5] Update post.controller.js --- server/src/controllers/post.controller.js | 105 ++++++---------------- 1 file changed, 27 insertions(+), 78 deletions(-) diff --git a/server/src/controllers/post.controller.js b/server/src/controllers/post.controller.js index 13c3f5b6..e7437f9f 100644 --- a/server/src/controllers/post.controller.js +++ b/server/src/controllers/post.controller.js @@ -218,94 +218,42 @@ if (!intent || (!content && !req.file && !hasPoll)) { let poll = undefined; if (pollQuestion && pollOptions) { - const parsedOptions = - typeof pollOptions === "string" - ? JSON.parse(pollOptions) - : pollOptions; - -if (!Array.isArray(parsedOptions)) { - return res.status(400).json({ - success: false, - message: "Poll options must be an array" - }); -} - -const cleanedOptions = parsedOptions - .map(option => option?.trim()) - .filter(Boolean); - -if (cleanedOptions.length < 2) { - return res.status(400).json({ - success: false, - message: "Poll requires at least 2 options" - }); -} - -if ( - pollExpiresAt && - new Date(pollExpiresAt) <= new Date() -) { - return res.status(400).json({ - success: false, - message: "Poll expiry must be in the future" - }); -} - -poll = { - question: pollQuestion.trim(), - options: cleanedOptions.map(option => ({ - text: option, - voters: [] - })), - expiresAt: pollExpiresAt || null -}; - const parsedOptions = - typeof pollOptions === "string" - ? JSON.parse(pollOptions) - : pollOptions; - -if (!Array.isArray(parsedOptions)) { - return res.status(400).json({ - success: false, - message: "Poll options must be an array" - }); -} - -const cleanedOptions = parsedOptions - .map(option => option?.trim()) - .filter(Boolean); - -if (cleanedOptions.length < 2) { - return res.status(400).json({ - success: false, - message: "Poll requires at least 2 options" - }); -} - -if ( - pollExpiresAt && - new Date(pollExpiresAt) <= new Date() -) { - return res.status(400).json({ - success: false, - message: "Poll expiry must be in the future" - }); -} const parsedOptions = typeof pollOptions === "string" ? JSON.parse(pollOptions) : pollOptions; - if (parsedOptions.length < 2) { + if (!Array.isArray(parsedOptions)) { return res.status(400).json({ success: false, - message: "Poll must contain at least 2 options" + message: "Poll options must be an array" + }); + } + + const cleanedOptions = parsedOptions + .map(option => option?.trim()) + .filter(Boolean); + + if (cleanedOptions.length < 2) { + return res.status(400).json({ + success: false, + message: "Poll requires at least 2 options" + }); + } + + if ( + pollExpiresAt && + new Date(pollExpiresAt) <= new Date() + ) { + return res.status(400).json({ + success: false, + message: "Poll expiry must be in the future" }); } poll = { - question: pollQuestion, - options: parsedOptions.map(option => ({ + question: pollQuestion.trim(), + options: cleanedOptions.map(option => ({ text: option, voters: [] })), @@ -313,6 +261,7 @@ if ( }; } + const post = await Post.create({ author: req.user.id, authorIsPrivate: req.user.isPrivate || false, @@ -1148,4 +1097,4 @@ export const getPollResults = asyncHandler(async (req, res) => { totalVotes, results }); -}); \ No newline at end of file +}); From 8769f374df4be9a446b4f3083287eef727372808 Mon Sep 17 00:00:00 2001 From: Jainiksha patel Date: Mon, 15 Jun 2026 19:07:32 +0530 Subject: [PATCH 2/5] Update user.controller.js --- server/src/controllers/user.controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/controllers/user.controller.js b/server/src/controllers/user.controller.js index 2367c6cb..77a0e082 100644 --- a/server/src/controllers/user.controller.js +++ b/server/src/controllers/user.controller.js @@ -738,7 +738,6 @@ export const searchUsers = asyncHandler(async (req, res) => { const { query, cursor, - location, sortBy } = req.query; From 57eee98dc4bb2a1ac5aefbb7fc96eab3f837d0d7 Mon Sep 17 00:00:00 2001 From: Jainiksha patel Date: Mon, 15 Jun 2026 19:08:45 +0530 Subject: [PATCH 3/5] Update user.routes.js --- server/src/routes/user.routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/user.routes.js b/server/src/routes/user.routes.js index 54b5ca26..36a4e4d3 100644 --- a/server/src/routes/user.routes.js +++ b/server/src/routes/user.routes.js @@ -21,7 +21,7 @@ userRouter.put("/:id/reject-request", authMiddleware, followActionLimiter, rejec userRouter.get("/all", authMiddleware, getAllUsers); userRouter.get("/search", searchLimiter, authMiddleware, searchUsers); userRouter.get("/analytics", authMiddleware, getUserAnalytics); -userRouter.get("/:username", optionalAuth, getUserProfile); +userRouter.get("/:username", getUserProfile); userRouter.get("/:id/followers", authMiddleware, getFollowers); userRouter.get("/:id/following", authMiddleware, getFollowing); From 62d5462c6f356e135a7b0d995b80e14c3f43291a Mon Sep 17 00:00:00 2001 From: Jainiksha patel Date: Sat, 27 Jun 2026 17:31:31 +0530 Subject: [PATCH 4/5] Update post.controller.js --- server/src/controllers/post.controller.js | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/server/src/controllers/post.controller.js b/server/src/controllers/post.controller.js index c3278347..e66a0acd 100644 --- a/server/src/controllers/post.controller.js +++ b/server/src/controllers/post.controller.js @@ -130,14 +130,25 @@ const getTopPosts = (daysAgo, maxResults) => async (req, res) => { { $unwind: "$author" }, { $project: { - _id: 1, content: 1, image: 1, intent: 1, likes: 1, - commentsCount: 1, sharesCount: 1, likesCount: 1, - createdAt: 1, updatedAt: 1, poll: 1, - createdAt: 1, updatedAt: 1, - isEdited: 1, editedAt: 1, - "author._id": 1, "author.username": 1, "author.name": 1, - "author.surname": 1, "author.avatar": 1, - }, + _id: 1, + content: 1, + image: 1, + intent: 1, + likes: 1, + commentsCount: 1, + sharesCount: 1, + likesCount: 1, + createdAt: 1, + updatedAt: 1, + poll: 1, + isEdited: 1, + editedAt: 1, + "author._id": 1, + "author.username": 1, + "author.name": 1, + "author.surname": 1, + "author.avatar": 1, +} } ]); From 6344d2c7987e36236d89091b338dc05cec6347e8 Mon Sep 17 00:00:00 2001 From: Jainiksha patel Date: Sat, 27 Jun 2026 17:35:14 +0530 Subject: [PATCH 5/5] Update post.controller.js --- server/src/controllers/post.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/controllers/post.controller.js b/server/src/controllers/post.controller.js index e66a0acd..06136c2b 100644 --- a/server/src/controllers/post.controller.js +++ b/server/src/controllers/post.controller.js @@ -148,7 +148,7 @@ const getTopPosts = (daysAgo, maxResults) => async (req, res) => { "author.name": 1, "author.surname": 1, "author.avatar": 1, -} +}, } ]);