Skip to content

Commit

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

Removed userName check for temp/pollpostcomment
  • Loading branch information
Sebastian-Webster authored Oct 10, 2023
2 parents a257850 + f608471 commit eef3c96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
37 changes: 13 additions & 24 deletions controllers/Temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,12 @@ class TempController {
})
}

static #pollpostcomment = (userId, comment, userName, postId) => {
static #pollpostcomment = (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 @@ -716,23 +712,16 @@ class TempController {
//Find User
User.findOne({_id: {$eq: userId}}).lean().then(result => {
if (result) {
if (result.name == userName) {
async function findPolls() {
var objectId = new mongoose.Types.ObjectId()
console.log(objectId)
var commentForPost = {commentId: objectId, commenterId: userId, commentsText: comment, commentUpVotes: [], commentDownVotes: [], commentReplies: [], datePosted: Date.now()}
Poll.findOneAndUpdate({_id: {$eq: postId}}, { $push: { comments: commentForPost } }).then(function(){
return resolve(HTTPWTHandler.OK('Comment upload successful'))
})
.catch(err => {
console.error('An error occured while updating poll to have a new comment. The comment was:', commentForPost, '. THe error was:', err)
return resolve(HTTPWTHandler.serverError('An error occurred while posting comment. Please try again.'))
});
}
findPolls()
} else {
return resolve(HTTPWTHandler.badInput('A name based error occurred. Username in the database does not match userName provided'))
}
var objectId = new mongoose.Types.ObjectId()
console.log(objectId)
var commentForPost = {commentId: objectId, commenterId: userId, commentsText: comment, commentUpVotes: [], commentDownVotes: [], commentReplies: [], datePosted: Date.now()}
Poll.findOneAndUpdate({_id: {$eq: postId}}, { $push: { comments: commentForPost } }).then(function(){
return resolve(HTTPWTHandler.OK('Comment upload successful'))
})
.catch(err => {
console.error('An error occured while updating poll to have a new comment. The comment was:', commentForPost, '. THe error was:', err)
return resolve(HTTPWTHandler.serverError('An error occurred while posting comment. Please try again.'))
});
} else {
return resolve(HTTPWTHandler.notFound('Could not find a user with your user id'))
}
Expand Down Expand Up @@ -6456,8 +6445,8 @@ class TempController {
return await this.#searchforpollposts(userId, pubId, previousPostId)
}

static pollpostcomment = async (userId, comment, userName, postId) => {
return await this.#pollpostcomment(userId, comment, userName, postId)
static pollpostcomment = async (userId, comment, postId) => {
return await this.#pollpostcomment(userId, comment, postId)
}

static pollpostcommentreply = 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 @@ -1064,7 +1064,7 @@ router.post('/pollpostcomment', rateLimiters['/pollpostcomment'], (req, res) =>
const worker = new Worker(workerPath, {
workerData: {
functionName: 'pollpostcomment',
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 eef3c96

Please sign in to comment.