solution#514
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
This requires changes because the core requirement of the task, which was to implement full CRUD functionality for categories, is missing. The submitted code only contains the implementation for users and expenses from the previous task.
To meet the requirements, you need to:
- Create a new
Categorymodel and its corresponding database table. - Implement a repository, controller, and router to handle the CRUD operations for categories (e.g., at a
/categoriesendpoint). - Update the
Expense.model.jsto reference a category via a foreign key (e.g.,categoryId) instead of using a simple string field. - Register the new category router in
src/createServer.js.
Also, please note a smaller issue in src/controllers/expenses.controller.js: res.send(204) should be res.sendStatus(204) to correctly send a response with no body.
The existing code is a good foundation, but the main feature for this task needs to be implemented.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| const { models } = require('../models/models.js'); | ||
| const Expense = models.Expense; | ||
|
|
||
| const getAll = (filterParams = {}) => { | ||
| return Expense.findAll({ where: filterParams }); | ||
| }; | ||
|
|
||
| const create = (data) => { | ||
| return Expense.create(data); | ||
| }; | ||
|
|
||
| const getById = (id) => { | ||
| return Expense.findByPk(id); | ||
| }; | ||
|
|
||
| const remove = (id) => { | ||
| return Expense.destroy({ where: { id } }); | ||
| }; | ||
|
|
||
| const update = (id, data) => { | ||
| return Expense.update(data, { where: { id }, returning: true }); | ||
| }; | ||
|
|
||
| module.exports = { | ||
| getAll, | ||
| create, | ||
| getById, | ||
| remove, | ||
| update, | ||
| }; |
There was a problem hiding this comment.
The core requirement of this task is to implement CRUD functionality for categories. This includes creating a Category model, a repository for it, a controller, and router. None of these have been added to the project. The current files only show the implementation for users and expenses.
| app.use(cors(), express.json()); | ||
|
|
||
| app.use('/users', usersRouter); | ||
| app.use('/expenses', expensesRouter); |
There was a problem hiding this comment.
The task requires implementing CRUD operations for categories, but the router for the /categories endpoint has not been added to the server.
| case 'spentAt': | ||
| return isDate(o[k]); | ||
| case 'title': | ||
| case 'category': |
There was a problem hiding this comment.
The task requires implementing a full CRUD for categories. This implies 'category' should be its own resource (with a model, DB table, etc.), not just a string property of an expense. You would then reference it using an ID (e.g., categoryId) and validate that ID here.
| return; | ||
| } | ||
|
|
||
| res.send(204); |
There was a problem hiding this comment.
Using res.send(204) is not the correct way to send a 'No Content' response. This method will send a response with a body containing the text '204'. A 204 response must not have a body. Please use res.sendStatus(204) instead, which correctly sets the status and ensures no body is sent.
| category: { | ||
| type: DataTypes.STRING, | ||
| }, |
There was a problem hiding this comment.
To properly manage categories with full CRUD functionality, they should be a separate entity in the database. Instead of a STRING type for the category name, you should have a categoryId field here that acts as a foreign key to a new Category table. You'll need to create a Category.model.js file for this new entity.
No description provided.