-
Notifications
You must be signed in to change notification settings - Fork 512
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 - FMS #486
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 job, it's working well 🌻
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 idea breaking this out 👍
|
||
// Mongoose model | ||
const Thought = mongoose.model("Thought", ThoughtSchema); | ||
export default Thought; |
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.
It's good practice to always leave an empty line at the end of each JS file
app.use((req, res, next) => { | ||
if (mongoose.connection.readyState === 1) { | ||
next(); | ||
} else { | ||
res.status(503).json({ error: "Service unavailable" }); | ||
} | ||
}); |
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.
👍
.sort({ createdAt: "desc" }) | ||
.limit(20) | ||
.exec(); | ||
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 would be nice here too (and some error handling)
|
||
if (thought) { | ||
// Add one like | ||
thought.hearts++; |
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.
Here you could've used $inc
thought.hearts++; | ||
// Save thought object | ||
thought.save(); | ||
res.json(thought); |
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.
Status code would be nice here too
Netlify link
https://happy-thoughts-fms.netlify.app/
Render link
https://project-happy-thoughts-api-rn3z.onrender.com)