-
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
Initial commit #2
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.
Good PR. Some things can be improved.
Overall nicely done.
const [createdTodos, collaboratedTodos] = await Promise.all([ | ||
ToDo.find({ createdBy: req.user._id }).select("_id title"), | ||
ToDo.find({ | ||
collaborators: req.user._id, | ||
}).select("_id 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.
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 }); |
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.
use exec commands they slightly increase the speed.
class BackendError extends Error { | ||
constructor(statusCode = 500, message = "An error occurred") { | ||
super(); | ||
this.message = message; | ||
this.statusCode = statusCode; | ||
} | ||
} | ||
module.exports = BackendError; |
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.
nice one :)
if (username == null) throw new BackendError(400, "Username is required"); | ||
if (!username) throw new BackendError(400, "Username cannot be blank"); |
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.
combine them into one. Also, " " will pass both the tests. Be sure to check these cases.
todo.collaborators | ||
.filter((user) => (user ? true : false)) | ||
.some((userId) => userId.toString() == id); |
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.
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; |
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.
Use strict equality checkers.
Marks: |
I have completed these tasks
For TASK 2, I have used username because sharing username is easier than sharing ID
Request Object (Sample):