Skip to content

add task solution#507

Open
4xmplme wants to merge 5 commits intomate-academy:masterfrom
4xmplme:develop
Open

add task solution#507
4xmplme wants to merge 5 commits intomate-academy:masterfrom
4xmplme:develop

Conversation

@4xmplme
Copy link
Copy Markdown

@4xmplme 4xmplme commented Mar 31, 2026

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because the primary requirement of this task—implementing full CRUD functionality for categories—is missing from your submission. While the existing code for users and expenses is well-structured, the new feature has not been added.

To complete the task, you'll need to:

  • Create a new Category model.
  • Implement the corresponding service, controller, and router for categories.
  • Ensure the new routes are registered in src/createServer.js.
  • Add the new Category model to the database synchronization script in src/setup.js.

Please implement these missing pieces to manage categories as required by the task description.


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/createServer.js

app.use(express.json());
app.use('/users', routes.usersRouter);
app.use('/expenses', routes.expensesRouter);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The new routes for managing categories are missing. Based on the task requirements, you should add a new router here for the /categories endpoint.

Comment thread src/controllers/index.js
Comment on lines +4 to +7
module.exports = {
usersController,
expensesController,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The task requires implementing CRUD operations for categories. This would involve creating a categoriesController, which should be imported and exported from this file.

Comment thread src/services/index.js
Comment on lines +4 to +7
module.exports = {
usersService,
expensesService,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The task is to add CRUD functionality for categories. This would require a new categories.service.js file. Once created, the categoriesService should be imported and exported from this index file.

Comment thread src/routes/index.js
Comment on lines +4 to +7
exports.routes = {
usersRouter,
expensesRouter,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

According to the task requirements, you need to implement CRUD for categories. This file should import the categoriesRouter from its corresponding route file and include it in the exported routes object.

Comment thread src/setup.js Outdated
Comment on lines +1 to +4
const { User, Expense } = require('./models');

User.sync({ force: true });
Expense.sync({ force: true });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The new Category model, which is a core part of the task, is not being synchronized with the database here. You need to import the Category model and add a Category.sync({ force: true }) call.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

The category CRUD implementation is incomplete because the routes are not registered in the server, which is a critical blocker preventing the feature from working. Specifically, src/routes/index.js does not export categoriesRouter, so it cannot be imported and used in src/createServer.js. Additionally, src/createServer.js is missing the required route registration: app.use('/categories', routes.categoriesRouter);. Without these two changes, the /categories endpoints will be completely inaccessible, violating the core task requirement to ensure new routes are registered in src/createServer.js. Other integration gaps — like missing exports for categoriesController in src/controllers/index.js and categoriesService in src/services/index.js — also reduce consistency and maintainability. Please add the missing exports and route registration to complete the integration.


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

return res.sendStatus(400);
}

const category = await categoriesService.create(name);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categories router is not registered in the server. The task requires ensuring new routes are registered in createServer.js.

const { categoriesService } = require('../services/categories.service');

const create = async (req, res) => {
const { name } = req.body;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categories router is missing from exports. Need to export categoriesRouter here so it can be used in createServer.js.

Comment thread src/controllers/users.controller.js Outdated
Comment on lines +1 to +6
const { usersService } = require('../services/users.service');

const create = async (req, res) => {
const { name } = req.body;

if (!name) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesController is not exported in the controllers index file - other parts of the app cannot import it

Comment thread src/controllers/users.controller.js Outdated
Comment on lines +1 to +7
const { usersService } = require('../services/users.service');

const create = async (req, res) => {
const { name } = req.body;

if (!name) {
return res.sendStatus(400);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Need to add categoriesController export here to make it available to routes

Comment on lines +5 to +9
const { userId, spentAt, title, amount, category, note } = req.body;
const user = await usersService.getOne(userId);

if (!userId || !user) {
return res.sendStatus(400);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/routes/index.js is missing export for categoriesRouter

Comment on lines +10 to +12
}

const expense = await expensesService.create({
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/createServer.js is missing route registration for categoriesRouter

Comment thread src/controllers/expenses.controller.js Outdated
Comment on lines +6 to +8
const user = await usersService.getOne(userId);

if (!userId || !user) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/services/index.js is missing export for categoriesService

Comment thread src/controllers/expenses.controller.js Outdated
Comment on lines +6 to +8
const user = await usersService.getOne(userId);

if (!userId || !user) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

src/controllers/index.js is missing export for categoriesController

Comment thread src/controllers/index.js

module.exports = {
usersController,
expensesController,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesRouter is not exported from src/routes/index.js. Only usersRouter and expensesRouter are exported, but categoriesRouter needs to be added to make it available for registration.

Comment thread src/controllers/index.js
module.exports = {
usersController,
expensesController,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesController is not imported or exported from src/controllers/index.js. Without exporting it, other parts of the application cannot access the category controller.

Comment thread src/controllers/index.js
const { expensesController } = require('./expenses.controller');

module.exports = {
usersController,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesService is not exported from src/services/index.js. Without exporting it, the controller cannot access the category service methods.

type: DataTypes.INTEGER,
allowNull: false,
},
title: {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categories router is not registered in the server. The task explicitly requires: 'Ensure the new routes are registered in src/createServer.js'. Add: app.use('/categories', routes.categoriesRouter);

Comment thread src/createServer.js
Comment on lines +10 to +11
app.use('/users', routes.usersRouter);
app.use('/expenses', routes.expensesRouter);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categories router is NOT registered in the server. The task requires: 'Ensure the new routes are registered in src/createServer.js'. Currently only /users and /expenses are registered. Need to add: app.use('/categories', routes.categoriesRouter); after line 10.

Comment on lines +1 to +6
const { Router } = require('express');
const { expensesController } = require('./../controllers/expenses.controller');

const expensesRouter = Router();

expensesRouter.post('/', expensesController.create);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categories router is not imported and exported. Need to add: const { categoriesRouter } = require('./categories.route'); and add categoriesRouter to the exports object.

Comment thread src/models/User.model.js
Comment on lines 1 to +6
'use strict';

const { sequelize } = require('../db.js');
const { sequelize } = require('../db');
const { DataTypes } = require('sequelize');

const User = sequelize.define(
// your code goes here
);
const User = sequelize.define('User', {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesRouter is NOT exported from src/routes/index.js. Currently only usersRouter and expensesRouter are exported. Need to add: const { categoriesRouter } = require('./categories.route'); and add categoriesRouter to the exports object.

Comment thread src/routes/index.js
Comment on lines +1 to +6
const { usersRouter } = require('./users.route');
const { expensesRouter } = require('./expenses.route');

exports.routes = {
usersRouter,
expensesRouter,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categories router is not exported from src/routes/index.js. Currently only usersRouter and expensesRouter are exported. Need to add: const { categoriesRouter } = require('./categories.route'); and include it in exports.

Comment thread src/routes/index.js

exports.routes = {
usersRouter,
expensesRouter,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Need to export categoriesRouter in the routes object to make it available for registration in createServer.js.

Comment on lines +1 to +6
const { Router } = require('express');
const {
categoriesController,
} = require('./../controllers/categories.controller');

const categoriesRouter = Router();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesRouter is NOT exported. Need to import it and add it to exports: const { categoriesRouter } = require('./categories.route'); and add categoriesRouter to the exports object. Without this, the categories route cannot be used in createServer.js

Comment on lines +1 to +6
const { Category } = require('../models');

const normalize = ({ id, name }) => ({ id, name });

const create = async (name) => {
const category = await Category.create({ name });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesRouter is NOT exported. Need to import it and add to exports: const { categoriesRouter } = require('./categories.route'); and add categoriesRouter to the exports object.

Comment thread src/routes/users.route.js
Comment on lines +1 to +6
const { Router } = require('express');
const { usersController } = require('./../controllers/users.controller');

const usersRouter = Router();

usersRouter.post('/', usersController.create);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesService is NOT exported from src/services/index.js. Currently only usersService and expensesService are exported. Need to add: const { categoriesService } = require('./categories.service'); and include it in the exports.

Comment thread src/services/index.js
Comment on lines +1 to +6
const { usersService } = require('./users.service');
const { expensesService } = require('./expenses.service');

module.exports = {
usersService,
expensesService,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The categoriesService is not exported from src/services/index.js. Need to add: const { categoriesService } = require('./categories.service'); and include it in the exports.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

I am approving your solution as an educational override to help you move forward, but please take a moment to review the feedback below.

Excellent work addressing all the integration issues from the previous review! The category CRUD functionality is now fully implemented and works well.

There's one small improvement to consider in src/controllers/categories.controller.js. The update function is missing validation for the request body. If a client tries to update a category without providing a name, it could cause an issue. It's a good practice to add a check to ensure req.body.name is present before proceeding, just like you did in the create function.

This is a minor point in an otherwise excellent submission. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

res.send(categoriesService.normalize(category));
};

const update = async (req, res) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's a good practice to validate the request body here, similar to how you've done it in the create function. What would happen if a client sends a request to update a category without providing a name? Consider adding a check to ensure req.body.name is present and returning a 400 Bad Request if it's not.

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