From e81fe06f9132a5210aec4436f8d3351d82e29de1 Mon Sep 17 00:00:00 2001 From: Sebastian-Webster Date: Tue, 10 Oct 2023 18:14:21 +1300 Subject: [PATCH 1/2] temp/imagepostcomment now returns newly made comment --- controllers/Temp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/Temp.js b/controllers/Temp.js index c99e4e71..14018783 100644 --- a/controllers/Temp.js +++ b/controllers/Temp.js @@ -1679,10 +1679,10 @@ class TempController { if (result) { const objectId = new mongoose.Types.ObjectId() console.log(objectId) - var commentForPost = {commentId: objectId, commenterId: userId, commentsText: comment, commentUpVotes: [], commentDownVotes: [], commentReplies: [], datePosted: Date.now()} + const commentForPost = {commentId: objectId, commenterId: userId, commentsText: comment, commentUpVotes: [], commentDownVotes: [], commentReplies: [], datePosted: Date.now()} ImagePost.findOneAndUpdate({_id: {$eq: postId}}, { $push: { comments: commentForPost } }).then(function(){ console.log("SUCCESS1") - return resolve(HTTPWTHandler.OK('Comment upload successful')) + return resolve(HTTPWTHandler.OK('Comment upload successful', commentForPost)) }) .catch(err => { console.error('An error occurred while pushing comment object:', commentForPost, 'to comments field for image with id:', postId, '. The error was:', err) From 209c33d2780376bd6477c9ea89340f960a5f56ad Mon Sep 17 00:00:00 2001 From: Sebastian-Webster Date: Tue, 10 Oct 2023 18:15:47 +1300 Subject: [PATCH 2/2] Stringify ids before being sent --- controllers/Temp.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/Temp.js b/controllers/Temp.js index 14018783..35646680 100644 --- a/controllers/Temp.js +++ b/controllers/Temp.js @@ -1682,6 +1682,8 @@ class TempController { const commentForPost = {commentId: objectId, commenterId: userId, commentsText: comment, commentUpVotes: [], commentDownVotes: [], commentReplies: [], datePosted: Date.now()} ImagePost.findOneAndUpdate({_id: {$eq: postId}}, { $push: { comments: commentForPost } }).then(function(){ console.log("SUCCESS1") + commentForPost.commentId = String(commentForPost.commentId) + commentForPost.commenterId = String(commentForPost.commenterId) return resolve(HTTPWTHandler.OK('Comment upload successful', commentForPost)) }) .catch(err => {