Skip to content

Comments

Happy thoughts API#45

Open
SaraEnderborg wants to merge 14 commits intoTechnigo:masterfrom
SaraEnderborg:master
Open

Happy thoughts API#45
SaraEnderborg wants to merge 14 commits intoTechnigo:masterfrom
SaraEnderborg:master

Conversation

@SaraEnderborg
Copy link

@SaraEnderborg SaraEnderborg commented Feb 8, 2026

Copy link

@sandrahagevall sandrahagevall left a comment

Choose a reason for hiding this comment

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

Great job Sara! I think you have done a well-structured and clear API, which is easy to follow. I don’t have much to add since your code works well, but I’ve included a few nice-to-have improvement suggestions :) Well done!

Side note: I noticed that your Render-link was missing in the pull-request.


const router = express.Router();

router.post("/user-signup", async (req, res) => {

Choose a reason for hiding this comment

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

Since the base route is already /users, you could make it more RESTful by using /signup, instead of /user-signup.

}
});

router.post("/user-login", async (req, res) => {

Choose a reason for hiding this comment

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

Same with this one, /login instead of /user-login

Comment on lines +71 to +80
if (user && bcrypt.compareSync(password, user.password)) {
res.json({
success: true,
message: "Login successful",
response: {
username: user.username,
email: user.email,
userId: user._id,
accessToken: user.accessToken,
},

Choose a reason for hiding this comment

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

Could explicitly use res.status(200).json for clarity and consistency with the error response.

});
}

const deletedThought = await Thoughts.findByIdAndDelete(id);

Choose a reason for hiding this comment

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

Everything works as expected here. As a nice-to-have improvement, you could link thoughts to the user who created them, making it possible to update or delete only your own thoughts.

}

try {
const updatedThought = await Thoughts.findByIdAndUpdate(

Choose a reason for hiding this comment

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

This is what I referred to in the comment on R127

Comment on lines +18 to +25
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

if (!emailRegex.test(email)) {
return res.status(400).json({
success: false,
message: "invalid email format",
});
}

Choose a reason for hiding this comment

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

Nice that you have this check for the format of the email!

const { id } = req.params;

try {
if (!mongoose.Types.ObjectId.isValid(id)) {

Choose a reason for hiding this comment

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

I like that you validate the id before fetching the thought 👍

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