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

Initial commit #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aditya-chhaparia
Copy link

@aditya-chhaparia aditya-chhaparia commented Aug 2, 2021

I have completed these tasks

  • Basic endpoints
  • Collaborator feature

For TASK 2, I have used username because sharing username is easier than sharing ID

Request Object (Sample):

{
    "username": "Username_of_the_collaborator"
}

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.

Good PR. Some things can be improved.
Overall nicely done.

Comment on lines +12 to +18
const [createdTodos, collaboratedTodos] = await Promise.all([
ToDo.find({ createdBy: req.user._id }).select("_id title"),
ToDo.find({
collaborators: req.user._id,
}).select("_id title"),
,
]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Mongodb $or mehthod for this.

const { title } = req.body;
if (title == null) throw new BackendError(400, "Title is required");
if (!title) throw new BackendError(400, "Title cannot be blank");
const newTodo = new ToDo({ title, createdBy: req.user._id });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use exec commands they slightly increase the speed.

Comment on lines +1 to +8
class BackendError extends Error {
constructor(statusCode = 500, message = "An error occurred") {
super();
this.message = message;
this.statusCode = statusCode;
}
}
module.exports = BackendError;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one :)

Comment on lines +35 to +36
if (username == null) throw new BackendError(400, "Username is required");
if (!username) throw new BackendError(400, "Username cannot be blank");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine them into one. Also, " " will pass both the tests. Be sure to check these cases.

Comment on lines +6 to +8
todo.collaborators
.filter((user) => (user ? true : false))
.some((userId) => userId.toString() == id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use todo.collaborators.includes() instead of the above.

// All the given method require token.
// So be sure to check for it before doing any stuff
// HINT: Create a middleware for above :)
const isCreater = (todo, id) => todo.createdBy.toString() == id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict equality checkers.

@K-Kumar-01
Copy link
Collaborator

Marks:
Task-1: 95
Task-2: 98

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