Skip to content

Commit

Permalink
Merge pull request #169 from SquareTable/163-remove-username-check-fr…
Browse files Browse the repository at this point in the history
…om-tempthreadpostcomment

Removed userName check fro temp/threadpostcomment
  • Loading branch information
Sebastian-Webster authored Oct 10, 2023
2 parents eef3c96 + ab18dd8 commit 170d985
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
36 changes: 14 additions & 22 deletions controllers/Temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3497,16 +3497,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}`))
}
Expand All @@ -3528,21 +3524,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'))
}
Expand Down Expand Up @@ -6589,8 +6581,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) => {
Expand Down
2 changes: 1 addition & 1 deletion routes/Temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
})

Expand Down

0 comments on commit 170d985

Please sign in to comment.