From ab18dd8d3b785a979fcf9722b36fda8edf218658 Mon Sep 17 00:00:00 2001 From: Sebastian-Webster Date: Tue, 10 Oct 2023 18:02:12 +1300 Subject: [PATCH] Removed userName check fro temp/threadpostcomment --- controllers/Temp.js | 36 ++++++++++++++---------------------- routes/Temp.js | 2 +- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/controllers/Temp.js b/controllers/Temp.js index 1f5d4816..a03b31a7 100644 --- a/controllers/Temp.js +++ b/controllers/Temp.js @@ -3523,16 +3523,12 @@ class TempController { }) } - static #threadpostcomment = (userId, comment, userName, postId) => { + static #threadpostcomment = (userId, comment, postId) => { return new Promise(resolve => { if (typeof comment !== 'string') { return resolve(HTTPWTHandler.badInput(`comment must be a string. Provided type: ${typeof comment}`)) } - if (typeof userName !== 'string') { - return resolve(HTTPWTHandler.badInput(`userName must be a string. Provided type: ${typeof userName}`)) - } - if (typeof postId !== 'string') { return resolve(HTTPWTHandler.badInput(`postId must be a string. Provided type: ${typeof postId}`)) } @@ -3554,21 +3550,17 @@ class TempController { //Find User User.findOne({_id: {$eq: userId}}).lean().then(result => { if (result) { - if (result.name == userName) { - var objectId = new mongoose.Types.ObjectId() - console.log(objectId) - var commentForPost = {commentId: objectId, commenterId: userId, commentsText: comment, commentUpVotes: [], commentDownVotes: [], commentReplies: [], datePosted: Date.now()} - Thread.findOneAndUpdate({_id: {$eq: postId}}, { $push: { comments: commentForPost } }).then(function(){ - console.log("SUCCESS1") - return resolve(HTTPWTHandler.OK('Comment upload successful')) - }) - .catch(err => { - console.error('An error occurred while adding comment object:', commentForPost, "to thread's comments with id:", postId, '. The error was:', err) - return resolve(HTTPWTHandler.serverError('An error occurred while adding comment to post. Please try again.')) - }); - } else { - return resolve(HTTPWTHandler.notFound('name in database does not match up with provided userName')) - } + var objectId = new mongoose.Types.ObjectId() + console.log(objectId) + var commentForPost = {commentId: objectId, commenterId: userId, commentsText: comment, commentUpVotes: [], commentDownVotes: [], commentReplies: [], datePosted: Date.now()} + Thread.findOneAndUpdate({_id: {$eq: postId}}, { $push: { comments: commentForPost } }).then(function(){ + console.log("SUCCESS1") + return resolve(HTTPWTHandler.OK('Comment upload successful')) + }) + .catch(err => { + console.error('An error occurred while adding comment object:', commentForPost, "to thread's comments with id:", postId, '. The error was:', err) + return resolve(HTTPWTHandler.serverError('An error occurred while adding comment to post. Please try again.')) + }); } else { return resolve(HTTPWTHandler.notFound('Could not find user with provided userId')) } @@ -6615,8 +6607,8 @@ class TempController { return await this.#downvotethread(userId, threadId) } - static threadpostcomment = async (userId, comment, userName, postId) => { - return await this.#threadpostcomment(userId, comment, userName, postId) + static threadpostcomment = async (userId, comment, postId) => { + return await this.#threadpostcomment(userId, comment, postId) } static threadpostcommentreply = async (userId, comment, userName, postId, commentId) => { diff --git a/routes/Temp.js b/routes/Temp.js index 77e487b2..2f11dcbc 100644 --- a/routes/Temp.js +++ b/routes/Temp.js @@ -1719,7 +1719,7 @@ router.post('/threadpostcomment', rateLimiters['/threadpostcomment'], (req, res) const worker = new Worker(workerPath, { workerData: { functionName: 'threadpostcomment', - functionArgs: [req.tokenData, req.body.comment, req.body.userName, req.body.postId] + functionArgs: [req.tokenData, req.body.comment, req.body.postId] } })