Skip to content

Conversation

HolaCarmensita
Copy link

… lektionen igår, enklare! Ändrade test-scriptet så det använden babel.node
Copy link

@llindallarsson llindallarsson left a comment

Choose a reason for hiding this comment

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

Hey Casandra, so nice to finally review your code! ⭐️ Here's my thoughts about it:

General feedback
Overall, the code is well-structured, consistent, and easy to follow. The use of async/await is consistent, the REST endpoints are clearly separated, and the error handling is well-implemented. Variable naming is clear, and the use of Mongoose’s populate() is a good choice for retrieving related user information.

Identified issues and improvement suggestions

1. Message length validation inconsistency

  • In addThought (Thought controller), the validation states that the message length must be between 4 and 140 characters.
  • In the Thought model, the message field has a minlength of 5, which means the two validations are not aligned.
  • Recommendation: Align the validation rules in both the controller and the model to avoid confusion and ensure consistent behavior.

2. Missing validation in updateThought

  • The updateThought function does not validate the message length at all. This allows updating a thought with a message that would not pass the creation validation.
  • Recommendation: Add the same length validation as in addThought to maintain data integrity.

3. createdBy field set to required: false

  • In the Thought model, the createdBy field is optional. This allows the creation of posts without a logged-in user.
  • Recommendation: If your application requires authentication for posting thoughts, set required: true for the createdBy field. If anonymous posting is allowed, ensure there is proper handling in the API to manage such posts.

Copy link

@JennieDalgren JennieDalgren left a comment

Choose a reason for hiding this comment

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

Really good job with this project. Your code is well strcutred and easy to follow. The addons in the frontend is also super nice. I like the icons for edit and delete and also the descripiton of the app it self. You have thought about the small things as well as well structured code and testing!

Great work ⭐️

@@ -0,0 +1,124 @@
import assert from 'assert';

Choose a reason for hiding this comment

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

Nice! ⭐


const happyRouter = express.Router();

//KOMIHÅG ATT URL börjar med /api/thoughts

Choose a reason for hiding this comment

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

stick to english in your comments, it helps the reviewer to understand ;)

Comment on lines +25 to +27
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: false,

Choose a reason for hiding this comment

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

great connection to the user collection here

Comment on lines +49 to +59
try {
const newThought = await Thought.create({
message,
createdBy: req.user._id,
// likes and createdAt will be set by defaults in the model
});

const populatedThought = await newThought.populate(
'createdBy',
'_id email'
);

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