Skip to content

Comments

Happy Thoughts with database#46

Open
Demijuls wants to merge 9 commits intoTechnigo:masterfrom
Demijuls:master
Open

Happy Thoughts with database#46
Demijuls wants to merge 9 commits intoTechnigo:masterfrom
Demijuls:master

Conversation

@Demijuls
Copy link

@Demijuls Demijuls commented Feb 8, 2026

Copy link

@Nicolinabl Nicolinabl left a comment

Choose a reason for hiding this comment

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

Nice work!
Good use of comments and structuring in your code, makes it easier for me to follow along. A next step could have been to split some of the code into different files for better organisation, but i still find it easy to navigate bc of your comments. Tested it with your frontend aswell and as far as i could see it all seems to work. I like that the icons for editing only shows when logged in, nice little extra touch for ui :)

mongoose.connect(mongoUrl);
mongoose.Promise = Promise;

// ---- Models ----

Choose a reason for hiding this comment

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

good structuring with comments. Makes it easier to follow along in your code as a reviewer :)

});
}

if (password.length < 8) {

Choose a reason for hiding this comment

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

nice extra touch with min length on password

// ---- Endpoints POST ----
// ---- Post a thought:
app.post("/thoughts", authenticateUser, async (req, res) => {
//This will only work if next() function is called from the authenticateUser

Choose a reason for hiding this comment

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

again, good use of comments

Comment on lines +77 to +91
const authenticateUser = async (req, res, next) => {
const user = await User.findOne;
const token = req.header("Authorization");
if (!token) {
return res.status(401).json({ message: "User is logged out" });
}

if (user) {
req.user = user;
next();
} else {
//user is matched and not authorized to do smth
res.status(401).json({ loggedOut: true });
}
};

Choose a reason for hiding this comment

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

try catch error handling would have been good here

// ---- / Models ----

// Start defining your routes here
// ---- Authentication function: only authorised users can add or like thoughts

Choose a reason for hiding this comment

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

a nice touch could have been to separate models, middleware and routes into separate files so it would be easier to maintain and look through.

});

// ---- Like a thought
app.post("/thoughts/:id/like", async (req, res) => {

Choose a reason for hiding this comment

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

Minor suggestion: using patch instead of post here.
"patch is typically used to update part of an existing resource" (e.g., incrementing hearts on a thought).

post still works though so im not sure it matters :)

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