-
Notifications
You must be signed in to change notification settings - Fork 516
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
Happy Thoughts API #480
Happy Thoughts API #480
Conversation
…nd only have the default value.
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 job with the happy thoughts API 🌻
.exec(); | ||
|
||
if (allThoughts.length > 0) { | ||
res.json(allThoughts); |
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.
A status code here would be nice
|
||
// Input Validation | ||
if (!message || typeof message !== "string" || message.trim().length === 0) { | ||
return res.status(422).json({ |
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.
Never heard of 422 before, but I guess it works here 😅
const messages = Object.values(error.errors).map((err) => err.message); | ||
return res.status(400).json({ | ||
success: false, | ||
error: "Validation error", | ||
message: messages.join(". "), | ||
}); |
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 error handling 👍
const thought = await Thought.findByIdAndUpdate( | ||
thoughtId, | ||
{ $inc: { hearts: 1 } }, | ||
{ new: true, runValidators: true } | ||
); |
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.
⭐
Netlify link
https://mindful-and-happy.netlify.app/