-
Notifications
You must be signed in to change notification settings - Fork 514
Happy thoughts front and back end #489
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
Conversation
HIPPIEKICK
left a comment
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 Johanna, it works well 🌻
server.js
Outdated
| mongoose.Promise = Promise; | ||
| const Thought = mongoose.model("Thought", { | ||
| // this is the schema that tells the data base what kind of data we are expecting. like year-film, category and so on. | ||
| message: String, |
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 probably good idea to make this required
server.js
Outdated
| const Thought = mongoose.model("Thought", { | ||
| // this is the schema that tells the data base what kind of data we are expecting. like year-film, category and so on. | ||
| message: String, | ||
| hearts: Number, |
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.
And to make this default to 0
server.js
Outdated
| const thoughts = await Thought.find() | ||
| // sort by createdAt in descending order, so i get the newest thoughts first | ||
| .sort({ createdAt: "desc" }) | ||
| // limited to 20 thoughts | ||
| .limit(20) | ||
| .exec(); | ||
| res.json(thoughts); |
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 and clean! Would be nice with a status code here though
server.js
Outdated
| // create a new thought and save it to the database, mongo db will create a unique id for the thought. | ||
| const newThought = new Thought({ message: req.body.message, hearts: 0 }); | ||
| newThought.save().then(() => { | ||
| res.json(newThought); |
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.
And here
server.js
Outdated
| thought.hearts = thought.hearts + 1 | ||
| // here is where the heart is saved to the database | ||
| thought.save().then(() => { | ||
| 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.
And here (status code)
server.js
Outdated
| return; | ||
| } | ||
| // add a heart to the thought | ||
| thought.hearts = 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.
Here you could've used $inc 👀
Netlify link
https://happyythoughts.netlify.app/