Skip to content

Commit

Permalink
Removed userName check for temp/pollpostcomment
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Webster committed Oct 10, 2023
1 parent 34bec59 commit 8a3964d
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 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

0 comments on commit 8a3964d

Please sign in to comment.