Skip to content

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
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.

3 participants