Conversation
- Add PATCH /thoughts/:id for editing thoughts (owner only) - Add GET /categories for dynamic category list - Add username field to Thought schema - Fix typo in POST /thoughts (user._ud -> user._id) - Update API documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Users can now delete their own account - Also deletes all their thoughts when account is deleted Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Lists all users without sensitive fields (password, accessToken) - For debugging purposes only Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
| }); | ||
|
|
||
| const Thought = mongoose.model("Thought", thoughtSchema); | ||
|
|
There was a problem hiding this comment.
Nice touch with separating models for user and thought into different files, makes it easier to read through!
| }, | ||
| category: { | ||
| type: String, | ||
| default: "general" |
| password: { | ||
| type: String, | ||
| required: true, | ||
| minlength: 8 |
There was a problem hiding this comment.
Also thoughtful moment with giving the minlength to pasword, makes it more secure for users:)
| if (!user) { | ||
| return res.status(401).json({ | ||
| success: false, | ||
| error: "Invalid token" |
There was a problem hiding this comment.
Great that you made different messages for different errors, makes it easier to handle them
| authentication: { | ||
| description: "Some endpoints require authentication", | ||
| howTo: "Include 'Authorization' header with your access token", | ||
| protectedEndpoints: ["POST /thoughts", "PATCH /thoughts/:id", "DELETE /thoughts/:id"] |
There was a problem hiding this comment.
I see you hardcoded the endpoints instead of using listEndpoints here, and I it's a great idea to practice this already both for safety and for better documentation! I would probably suggest to still add listEndpoints(app) but only for internal use, and maybe console.log it to always be able to fast-check if hardcoded routes are up to date.
|
|
||
| app.get("/thoughts", async (req, res) => { | ||
| try { | ||
| const { category, sort, page = 1, limit = 20 } = req.query; |
There was a problem hiding this comment.
Nice touch with limiting amount of fetched thoughts
| try { | ||
| const { message, category } = req.body; | ||
|
|
||
| // First find the thought to check ownership |
There was a problem hiding this comment.
Great to see comments, makes it very easy to go through the code:)
| } | ||
| }); | ||
|
|
||
| // DELETE /users/:id - Delete user by ID (for debugging - remove in production!) |
There was a problem hiding this comment.
Again, great comment, especially since thosse last 2 end endpoints can seriously affect production:)
| }) | ||
| .catch((error) => { | ||
| console.error("Could not connect to MongoDB:", error.message) | ||
| }); |
There was a problem hiding this comment.
Overall very clean work all the way through, great user experience and nice error handling with clear messages. Keep it up!:)
Please include your Render link here.