RAT API / server to HAppy HToughts#23
RAT API / server to HAppy HToughts#23HolaCarmensita wants to merge 49 commits intoTechnigo:masterfrom
Conversation
… lektionen igår, enklare! Ändrade test-scriptet så det använden babel.node
… Patch unLikeThought is done and tested
…d remove thought to HappyRouter
…ctoring to have controller-folder. brb.
…the Auth middlewere to post and login
This reverts commit 53f5962.
llindallarsson
left a comment
There was a problem hiding this comment.
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
messagefield has aminlengthof 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
updateThoughtfunction does not validate themessagelength 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
createdByfield is optional. This allows the creation of posts without a logged-in user. - Recommendation: If your application requires authentication for posting thoughts, set
required: truefor thecreatedByfield. If anonymous posting is allowed, ensure there is proper handling in the API to manage such posts.
JennieDalgren
left a comment
There was a problem hiding this comment.
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'; | |||
|
|
||
| const happyRouter = express.Router(); | ||
|
|
||
| //KOMIHÅG ATT URL börjar med /api/thoughts |
There was a problem hiding this comment.
stick to english in your comments, it helps the reviewer to understand ;)
| type: mongoose.Schema.Types.ObjectId, | ||
| ref: 'User', | ||
| required: false, |
There was a problem hiding this comment.
great connection to the user collection here
| 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' | ||
| ); |
Please include your Render link here.