Skip to content

test#509

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

test#509
adonch wants to merge 4 commits intomate-academy:masterfrom
adonch:develop

Conversation

@adonch
Copy link
Copy Markdown

@adonch adonch commented Apr 2, 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

Thank you for your submission. While you've successfully set up the database connection and initial models, I'm requesting changes because the main requirement of the task is missing and existing features are not functional.

The primary goal was to implement CRUD functionality for categories, but the necessary model, service, controller, and router for categories have not been created. Additionally, the data services have not been correctly migrated to use PostgreSQL.

Here are the critical issues to address:

  • Missing Category Feature: Please implement the full CRUD functionality for categories as required by the task.
  • Broken Services:
    • In src/services/expenses.services.js, all functions still operate on an in-memory array. This entire file needs to be refactored to use the Sequelize Expense model for all database operations.
    • In src/services/users.services.js, the getUserById, deleteUser, and updateUser functions are using an undefined users variable, which will cause the application to crash. These methods must be updated to use the User model to interact with the database.

✨ 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.status(400).json({ message: 'Bad Request' });
}

const user = await usersService.getUserById(+id);
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 service method getUserById is not correctly implemented in users.services.js. It seems to be based on an in-memory array (users) that is not defined in the service file, instead of fetching data from the database. This will cause the application to crash. This function should be updated to use the User model to find a user by their ID in the database.

Comment thread src/controller/users.controller.js Outdated
if (!user) {
return res.status(404).json({ message: 'Not found' });
}
res.send(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.

For consistency with the getUsers controller, which normalizes user data, you should also normalize the single user object here before sending the response. Consider using res.send(usersService.normilize(user));.

return res.status(400).json({ message: 'Bad Request' });
}

const wasDeleted = await usersService.deleteUser(+id);
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 usersService.deleteUser method is not correctly implemented in users.services.js. It's using logic for an in-memory array and will not interact with the PostgreSQL database. This should be updated to use the User model to delete the user record.

Comment thread src/controller/users.controller.js Outdated
return res.status(400).json({ message: 'Bad Request' });
}

const updatedUser = await usersService.updateUser(+id, 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 usersService.updateUser method in users.services.js is not implemented to work with the database. It still contains logic for an in-memory array which will cause an error. This method needs to be updated to use the User model to update a user's data in PostgreSQL.

@@ -0,0 +1,121 @@
const expensesServices = require('../services/expenses.services');
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 imported expensesServices module still relies on an in-memory array for data storage. To meet the task requirement of using PostgreSQL, this service must be refactored to use the Expense Sequelize model for all its database operations.

Comment on lines +9 to +36
function getExpenses(data) {
const { userId, categories, from, to } = data;

return expenses.filter((expense) => {
if (userId && expense.userId !== userId) {
return false;
}

if (categories) {
const categoriesArray = Array.isArray(categories)
? categories
: [categories];

if (!categoriesArray.includes(expense.category)) {
return false;
}
}

if (from && new Date(expense.spentAt) < new Date(from)) {
return false;
}

if (to && new Date(expense.spentAt) > new Date(to)) {
return false;
}

return 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.

This function should be async and use the Expense model to query the database with the provided filters (e.g., using Expense.findAll({ where: ... })), not filter an in-memory array.

Comment thread src/services/expenses.services.js Outdated
Comment on lines +39 to +40
function getExpenseById(id) {
return expenses.find((expense) => expense.id === id);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This function should be async and use the Expense.findByPk(id) method to retrieve a single expense from the database.

Comment thread src/services/expenses.services.js Outdated
Comment on lines +43 to +56
function createExpense(userId, spentAt, title, amount, category, note) {
const newExpense = {
id: currentId++,
userId,
spentAt,
title,
amount,
category,
note: note || '',
};

expenses.push(newExpense);

return newExpense;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This function should be async and use Expense.create() to insert a new record into the database, rather than pushing to a local array.

Comment thread src/services/expenses.services.js Outdated
Comment on lines +59 to +68
function deleteExpense(id) {
const index = expenses.findIndex((expense) => expense.id === id);

if (index === -1) {
return false;
}

expenses.splice(index, 1);

return 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.

This function should be async and use Expense.destroy({ where: { id } }) to delete the record from the database. It should return the number of deleted rows.

Comment thread src/services/expenses.services.js Outdated
Comment on lines +71 to +85
function updateExpense(data) {
const { id, ...changes } = data;

const index = expenses.findIndex((expense) => expense.id === +id);

if (index === -1) {
return null;
}

expenses[index] = {
...expenses[index],
...changes,
};

return expenses[index];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This function should be async and use Expense.update(changes, { where: { id } }) to update the record in the database. It should also fetch and return the updated record.

adonch added 2 commits April 2, 2026 16:36
- Move user existence check in createExpense to validate input earlier.
- Normalize response for updated user and expense in respective controllers.
- Remove force sync from database models to prevent data loss.
- Update user service to return the updated user after modification.
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

Great work on refactoring the users and expenses services to use PostgreSQL with Sequelize! You've successfully addressed the previous feedback on migrating the existing features. However, I am requesting changes because the main requirement of this task—implementing full CRUD functionality for categories—is still missing. To complete the task, you need to create all the necessary components for this feature, including the model, service, controller, and router, and then register the router in src/createServer.js. Additionally, please correct the normilize typo to normalize in src/services/users.services.js for consistency.


✨ 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
try {
await sequelize.authenticate();
await User.sync();
await Expense.sync();
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 a Category model. Once you've created it, you'll also need to sync it with the database here, just like you've done for User and Expense.

Comment thread src/createServer.js Outdated
await sequelize.authenticate();
await User.sync();
await Expense.sync();
} catch (error) {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Swallowing errors can hide important problems during application startup. It's a good practice to at least log the error to the console, for example: console.error('DB sync failed:', error);.

Comment thread src/createServer.js
app.use(express.json());

app.use('/users', usersRouter);
app.use('/expenses', 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.

To make the category management available through the API, you'll need to create a router for categories and register it here using app.use('/categories', categoriesRouter);.

Comment thread src/controller/users.controller.js Outdated
async function getUsers(req, res) {
const users = await usersService.getUsers();

res.send(users.map(usersService.normilize));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's a small typo here. The function is named normilize, but the correct spelling is normalize. This typo exists in src/services/users.services.js and is used throughout this controller. For consistency with expenses.services.js and general code quality, it's a good idea to correct it.

Comment thread src/services/users.services.js Outdated
@@ -0,0 +1,39 @@
const { User } = require('../models/User.model');

function normilize({ id, 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.

There's a small typo in the function name here. For consistency with expenses.services.js and common spelling, this should be normalize.

- Fixed spelling of normilize to normalize in users.services.js.
- Updated users.controller.js to use the corrected normalize function.
- Enhanced error handling in createServer.js to log database sync failures.
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'm approving this submission as an educational override to help you progress, but please note the main feature is still missing. You did a great job correcting the normalize typo from the previous review!

The primary goal of implementing CRUD functionality for categories remains incomplete. To finish the task, you'll need to create the model, service, controller, and router for categories. Once those are built, remember to integrate them in src/createServer.js by importing the Category model, syncing it with the database, and registering the new categoriesRouter. Keep up the effort—you're on the right track!


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

Footnotes

  1. Rate AI review example

Comment thread src/createServer.js
Comment on lines +7 to +8
const { User } = require('./models/User.model');
const { Expense } = require('./models/Expense.model');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're missing the import for the Category model. It needs to be imported here to be used for database synchronization.

Comment thread src/createServer.js
Comment on lines +14 to +15
await User.sync();
await Expense.sync();
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 also needs to be synchronized with the database. Please add await Category.sync() here.

Comment thread src/createServer.js
Comment on lines +29 to +30
app.use('/users', usersRouter);
app.use('/expenses', 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 router for the categories feature is not registered. You need to import categoriesRouter and then use it with app.use() to expose the category endpoints.

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