Skip to content
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 front and back end #489

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

johannacatalinismith
Copy link

Copy link
Contributor

@HIPPIEKICK HIPPIEKICK left a 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
@@ -5,6 +5,16 @@ import mongoose from "mongoose";
const mongoUrl = process.env.MONGO_URL || "mongodb://localhost/project-mongo";
mongoose.connect(mongoUrl);
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,
Copy link
Contributor

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,
Copy link
Contributor

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
Comment on lines 32 to 38
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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants