Skip to content

Conversation

@JohannaBN
Copy link

@JohannaBN JohannaBN commented May 17, 2024

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.

Nice job with the happy thoughts API 🌻

.exec();

if (allThoughts.length > 0) {
res.json(allThoughts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A status code here would be nice


// Input Validation
if (!message || typeof message !== "string" || message.trim().length === 0) {
return res.status(422).json({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never heard of 422 before, but I guess it works here 😅

Comment on lines +96 to +101
const messages = Object.values(error.errors).map((err) => err.message);
return res.status(400).json({
success: false,
error: "Validation error",
message: messages.join(". "),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice error handling 👍

Comment on lines +118 to +122
const thought = await Thought.findByIdAndUpdate(
thoughtId,
{ $inc: { hearts: 1 } },
{ new: true, runValidators: true }
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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