Skip to content

Happy Thoughts API Project - Asako#36

Open
Appilistus wants to merge 15 commits intoTechnigo:masterfrom
Appilistus:master
Open

Happy Thoughts API Project - Asako#36
Appilistus wants to merge 15 commits intoTechnigo:masterfrom
Appilistus:master

Conversation

@Appilistus
Copy link

const sortOrder = order === "asc" ? 1 : -1

try {
const messages = await Message.find(query).sort({ [sortField]: sortOrder })

Choose a reason for hiding this comment

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

Really great work with combining the filtering and sorting! They work well combining together, and it's nice that you have some input validation and make sure they are always defined.

A maybe "nice-to-have thing" would be a message showing when there is nothing matching the filter criteria, so it's ultra clear for the user!

const newMessage = await new Message({
message: body.message,
hearts: 0,
userId: req.userId || null, // Set userId if authenticated, else null

Choose a reason for hiding this comment

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

Not sure if I'm thinking right here, but maybe you could just set null as default value of userId already in the user schema?

Comment on lines +152 to +153
if (message.likedByClients.includes(clientId)) {
return res.status(400).json({

Choose a reason for hiding this comment

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

Nice error handling here to make sure a user can only like a thought once! Would be nice if that error message was the same for the user on the frontend, as the "failed to send like" got me a bit confused at first!

router.patch("/:id/like", async (req, res) => {
const id = req.params.id
const authHeader = req.header("Authorization")
const clientId = req.header("X-Client-Id")
Copy link

@gabriellaberko gabriellaberko Feb 6, 2026

Choose a reason for hiding this comment

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

For a logged in user, will it also be a client ID (and not a user ID)? Or what is the authHeader for here? (just a question out of curiosity hehe :D)

Copy link

@gabriellaberko gabriellaberko left a comment

Choose a reason for hiding this comment

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

Well done! The code is really organized in the files and easy to follow. Sorting and filtering the thoughts works great, and you are making sure to include proper error handling in all the routes.

Some really minor improvements that popped up in my mind during the code review was only to make some of the errors more clear towards the user on the front-end side, as they are on the backend/in the console.

Other than that, it looks and behaves great. You can tell that you understand how everything go together!

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