From 70479974d6acd653465cf79584f8b00c64f28c3c Mon Sep 17 00:00:00 2001 From: Sebastian Webster Date: Fri, 15 Sep 2023 01:10:25 +1200 Subject: [PATCH] PollPost.processMultiplePostDataFromOneOwner now sends poll vote to client --- libraries/PollPost.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libraries/PollPost.js b/libraries/PollPost.js index 52293e6f..da2e6068 100644 --- a/libraries/PollPost.js +++ b/libraries/PollPost.js @@ -16,6 +16,25 @@ class PollPost { Upvote.findOne({postId: {$eq: post._id}, postFormat: "Poll", userPublicId: userRequesting.secondId}), Downvote.findOne({postId: {$eq: post._id}, postFormat: "Poll", userPublicId: userRequesting.secondId}), ]).then(([upvotes, downvotes, isUpvoted, isDownvoted]) => { + let votedFor = "None"; + if (post.optionOnesVotes.includes(userRequesting._id)) { + votedFor = "One" + } + if (post.optionTwosVotes.includes(userRequesting._id)) { + votedFor = "Two" + } + if (post.optionThreesVotes.includes(userRequesting._id)) { + votedFor = "Three" + } + if (post.optionFoursVotes.includes(userRequesting._id)) { + votedFor = "Four" + } + if (post.optionFivesVotes.includes(userRequesting._id)) { + votedFor = "Five" + } + if (post.optionSixesVotes.includes(userRequesting._id)) { + votedFor = "Six" + } const postObject = { ...post, optionOnesVotes: post.optionOnesVotes.length, @@ -32,7 +51,8 @@ class PollPost { upvoted: !!isUpvoted, downvoted: !!isDownvoted, isOwner: postOwner._id.toString() === userRequesting._id.toString(), - interacted: !!isUpvoted || !!isDownvoted + interacted: !!isUpvoted || !!isDownvoted, + votedFor } if (isUpvoted) {