-
Notifications
You must be signed in to change notification settings - Fork 517
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
Week 19: happy thoughts API #509
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.
Use mongoose methods when you can, otherwise - good job!
server.js
Outdated
// Example array of user references who have “liked” this thought | ||
likedUsers: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User' | ||
} | ||
], |
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 👍
server.js
Outdated
|
||
// Root endpoint - shows available endpoints in JSON | ||
app.get('/', (req, res) => { | ||
console.log('REQ.BODY =>', req.body); |
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.
No console.logs in production
server.js
Outdated
// Example toggle logic: if hearts is even, increment, otherwise decrement | ||
if (thought.hearts % 2 === 0) { | ||
thought.hearts += 1 | ||
} else { | ||
thought.hearts -= 1 | ||
} |
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.
What's the purpose of this? 👀
server.js
Outdated
app.post('/thoughts/:id/like', async (req, res) => { | ||
try { | ||
const { id } = req.params | ||
const thought = await Thought.findById(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.
Why not use findByIdAndUpdate for updating hearts directly instead of fetching, modifying, and saving? 🤔
API: https://project-happy-thoughts-api-hc1b.onrender.com/
Frontend: https://happiestthoughts.netlify.app/