-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completed both tasks #8
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing was not done properly. PR had many issues.
- Authentication wasn't working properly.
- Cannot distinguish which todo created by whom.
- Empty array when calling
getAllToDo
for newly created user.
|
||
// All the given method require token. | ||
// So be sure to check for it before doing any stuff | ||
// HINT: Create a middleware for above :) | ||
|
||
//ok lets create a middleware XD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
; )
catch(err){ | ||
return false; | ||
} | ||
}; | ||
const getAllToDo = async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I haven't created any todo, I get an empty array.
try{ | ||
const token = req.body.token || req.query.token || | ||
req.headers["x-access-token"] || req.headers.token || | ||
req.headers.authorization.split(' ')[1]; | ||
if (!token) | ||
return false; | ||
else | ||
return token; | ||
} | ||
catch(err){ | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be specific with the message. If i dont give any token, I should get no token provided
. If token is given, but invalid then message should be invalid token given
.
}; | ||
|
||
const createToDo = async (req, res) => { | ||
// Check for the token and create a todo | ||
// or throw error correspondingly | ||
const token = verification(req,res); | ||
if(token != false){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of token!=false
, use simply token
.
createdBy: foundToken.user}); | ||
newTodo.save(function(err){ | ||
if(!err) | ||
res.status(200).json({id: req.params.id, title: newTodo.title}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong details are being sent here. It will be newTodo._id
} | ||
else{ | ||
res.status(401).json({detail: "No such user found!!"}) | ||
} | ||
}; | ||
|
||
const createToDo = async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
able to create a todo with " "
,
}) | ||
} | ||
else | ||
res.status(401).json({detail: "No such user found!!"}) | ||
}; | ||
|
||
const getParticularToDo = async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am able to access todo using other tokens. A major flaw. Seems middleware would need update.
if(foundUsers){ | ||
users = []; | ||
foundUsers.forEach(function(user){ | ||
users.push({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not able to see which todo is created by whom by response only.
Marks: Authentication wasn't done properly which was the major reason. |
No description provided.