Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Arvind0302
Copy link

No description provided.

Copy link
Collaborator

@K-Kumar-01 K-Kumar-01 left a 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.

  1. Authentication wasn't working properly.
  2. Cannot distinguish which todo created by whom.
  3. 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
Copy link
Collaborator

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) => {
Copy link
Collaborator

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.

Comment on lines +10 to +20
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;
Copy link
Collaborator

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){
Copy link
Collaborator

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})
Copy link
Collaborator

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) => {
Copy link
Collaborator

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) => {
Copy link
Collaborator

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({
Copy link
Collaborator

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.

@K-Kumar-01
Copy link
Collaborator

Marks:
Task-1: 65
Task-2: 70

Authentication wasn't done properly which was the major reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants