diff --git a/server/src/controllers/post.controller.js b/server/src/controllers/post.controller.js index 93d160ad..06136c2b 100644 --- a/server/src/controllers/post.controller.js +++ b/server/src/controllers/post.controller.js @@ -130,12 +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, 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, +}, } ]); @@ -234,49 +247,50 @@ 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 parsedOptions = + typeof pollOptions === "string" + ? JSON.parse(pollOptions) + : pollOptions; -const cleanedOptions = parsedOptions - .map(option => option?.trim()) - .filter(Boolean); + if (!Array.isArray(parsedOptions)) { + return res.status(400).json({ + success: false, + message: "Poll options must be an array" + }); + } -if (cleanedOptions.length < 2) { - return res.status(400).json({ - success: false, - message: "Poll requires at least 2 options" - }); -} + const cleanedOptions = parsedOptions + .map(option => option?.trim()) + .filter(Boolean); -if ( - pollExpiresAt && - new Date(pollExpiresAt) <= new Date() -) { - return res.status(400).json({ - success: false, - message: "Poll expiry must be in the future" - }); -} + if (cleanedOptions.length < 2) { + return res.status(400).json({ + success: false, + message: "Poll requires at least 2 options" + }); + } -poll = { - question: pollQuestion.trim(), - options: cleanedOptions.map(option => ({ - text: option, - voters: [] - })), - expiresAt: pollExpiresAt || null -}; + 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 post = await Post.create({ author: req.user.id, authorIsPrivate: req.user.isPrivate || false, diff --git a/server/src/controllers/user.controller.js b/server/src/controllers/user.controller.js index bbfa5034..09c0e5d5 100644 --- a/server/src/controllers/user.controller.js +++ b/server/src/controllers/user.controller.js @@ -740,10 +740,10 @@ export const getSuggestedUsers = asyncHandler(async (req, res) => { export const searchUsers = asyncHandler(async (req, res) => { const { - query, - cursor, - sortBy - } = req.query; + query, + cursor, + sortBy +} = req.query; if (!query) { return res.json({