Skip to content

temporary solution#185

Open
eg598 wants to merge 3 commits intomate-academy:masterfrom
eg598:develop
Open

temporary solution#185
eg598 wants to merge 3 commits intomate-academy:masterfrom
eg598:develop

Conversation

@eg598
Copy link
Copy Markdown

@eg598 eg598 commented Mar 15, 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 application has several critical issues that prevent it from meeting the core requirements.

The main problem is that the core application logic in src/index.js is disconnected from the database layer you've built. It currently uses a temporary in-memory array for messages instead of your services, and the required API endpoints for managing users and rooms are not implemented. This means that data isn't being saved, and most of the required functionality is inaccessible.

Additionally, there are a few issues that will cause the server to crash:

  • A typo in the user model filename (user.nodel.js should be user.model.js) will prevent the app from starting. Please correct the filename and the corresponding imports in src/setup.js and src/services/user.service.js.
  • The update functions in src/services/user.service.js and src/services/room.service.js don't handle cases where an item is not found before trying to update it.

You've built a solid data layer with your models and services; the next step is to integrate them into your main server file to make the application functional.


✨ 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 on lines +18 to +19
if (!name) {
return res.status(404).send({ message: 'No name was provided' });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When the client fails to provide required data in the request body, it's considered a client-side error. The appropriate HTTP status code for this is 400 Bad Request, not 404 Not Found. The 404 code should be used when the requested resource itself cannot be found.

Comment on lines +30 to +31
if (!name) {
return res.status(404).send({ message: 'No name was provided' });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to the renameRoom function, a missing name in the request body should result in a 400 Bad Request status, as it indicates an error in the client's request. 404 Not Found is for when a resource is missing.

const { name } = req.body;

if (!name) {
return res.status(404).send({ message: 'No name was provided' });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When the client fails to provide a required field like name, it's considered a client-side error. The appropriate HTTP status code for this is 400 Bad Request, not 404 Not Found. The 404 status code should be used when the requested resource or endpoint itself cannot be found.

// res.send(message);
// };

const getAll = async (res, req) => {
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 parameters for an Express route handler should be (req, res). You have them in the wrong order, which will cause req.params to be undefined on the next line.


const messages = await Message.findAll({
where: { roomId },
order: [['createdAt', 'ASC']],
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 Message model doesn't have a createdAt field. Based on your model definition (src/models/message.model.js), you should order by the time field instead.

@@ -0,0 +1,23 @@
const { Message } = require('./models/message.model.js');
const { Room } = require('./models/room.model.js');
const { User } = require('./models/user.nodel.js');
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 appears to be a typo in the import path. The file for the user model is likely named user.model.js, but it's written as user.nodel.js here. This will cause a MODULE_NOT_FOUND error when the application starts.

};

const update = async (id, authorId, text, time, roomId) => {
const room = await getOne(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 getOne(id) function retrieves a Message instance, not a Room. To avoid confusion and potential errors, this variable should be renamed to something like message.

const update = async (id, name) => {
const room = await getOne(id);

return room.update({ 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.

If getOne(id) returns null (meaning no room was found), this line will throw a TypeError because you're trying to call .update() on null. This will cause an unhandled promise rejection and crash your application. You should add a check to ensure room exists before attempting to update it.

@@ -0,0 +1,30 @@
const { User } = require('../models/user.nodel.js');
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 appears to be a typo in the filename being imported. For consistency with your other model files (message.model.js, room.model.js), it should likely be user.model.js instead of user.nodel.js. You'll need to rename the file itself for this change to work.

const update = async (id, name) => {
const user = await getOne(id);

return user.update({ 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.

If a user with the given id is not found, getOne(id) will return null. Attempting to call .update() on null will cause a TypeError and crash the application. You should add a check to handle the case where the user does not exist before trying to update it.

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

You've made excellent progress refactoring the application to use a proper database structure with services and controllers! However, several critical issues, some of which were noted in the last review, are preventing the application from running and meeting the core requirements. I am requesting changes to address them.

Here are the main blockers:

  1. Server Won't Start: There is still a typo in the import path in src/services/user.service.js and src/setup.js. It should be user.model.js, not user.nodel.js.
  2. Server Crashes on Update: The update methods in user.service.js, room.service.js, and message.service.js do not check if an item exists before trying to update it. This will cause the server to crash if an invalid ID is used.
  3. Missing User Functionality: The user controller endpoints are not accessible because you haven't created and connected a user router in src/index.js. This means the requirement for a user to send their username is not met.
  4. Broken Route: The route to get all rooms (GET / in room.route.js) calls roomController.getAll, but this function is not defined in the controller, which will cause an error.

Please fix these issues to get the application working as expected. You're very close!


✨ 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 on lines +7 to +9
const messages = await Message.findAll({
where: { roomId },
});
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 maintain a clear separation of concerns, the controller should not interact directly with the model. All database operations should be encapsulated within the service layer. You should add a method to messageService to find all messages by roomId and call that method here.

Comment on lines +11 to +13
if (!messages) {
return res.status(404).send({ message: 'No messages found' });
}
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 findAll method returns an array. In JavaScript, an empty array [] is a truthy value, so this condition will never be met. If no messages are found, findAll returns an empty array, and your API will correctly send back [] with a 200 status code, which is the expected behavior. You can safely remove this check.

const time = new Date();

if (!authorId || !text || !roomId) {
return res.status(404).send({ message: 'Something went wrong' });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While this works, a 400 Bad Request status code is more semantically correct for indicating that the client provided invalid or incomplete data in the request. 404 Not Found is typically used when the requested resource itself doesn't exist.

return res.status(404).send({ message: 'No name was provided' });
}

const room = await roomService.update(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.

This will cause the application to crash if a room with the given id doesn't exist. The roomService.update method doesn't handle this case. You should first check if the room exists, similar to how you do in the deleteRoom function, before attempting to update it.

const { userService } = require('../services/user.service.js');

const getById = async (req, res) => {
const { id } = 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.

It's a common convention in REST APIs to pass resource identifiers like id through URL parameters (req.params) for GET requests, rather than in the request body. For example, the route would look like GET /users/:id.

const update = async (id, name) => {
const room = await getOne(id);

return room.update({ 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.

If getOne(id) returns null because the room doesn't exist, this line will throw a TypeError by trying to call .update() on null. This will crash the server. You need to add a check here to ensure room exists before you try to update it. If it doesn't exist, you could return null to signal to the controller that the update failed.

@@ -0,0 +1,30 @@
const { User } = require('../models/user.nodel.js');
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 import path contains a typo. The filename is user.model.js, not user.nodel.js. This was mentioned in the previous review and is a critical error that will prevent the application from starting.

Comment on lines +12 to +14
const user = await getOne(id);

return user.update({ 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.

This implementation does not handle the case where a user with the given id is not found. If getOne(id) returns null, calling user.update() on the next line will throw an error and crash the server. You need to add a check to ensure user is not null before trying to update it. This was also mentioned in the previous review.

router.patch('/:roomId', roomController.renameRoom);
router.post('/', roomController.createRoom);
router.delete('/:roomId', roomController.deleteRoom);
router.get('/', roomController.getAll);
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 route handler roomController.getAll does not exist in src/controllers/room.controller.js. Calling this route will result in a server error. You need to implement the getAll function in your room controller, which should probably call roomService.getAll() to fetch all the rooms.

@@ -0,0 +1,23 @@
const { Message } = require('./models/message.model.js');
const { Room } = require('./models/room.model.js');
const { User } = require('./models/user.nodel.js');
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 is a typo in this file path. The file should be user.model.js, not user.nodel.js. This is a critical error that will prevent the application from running and was mentioned in the previous review.

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 this submission as an educational override to help you progress, but there are a few critical issues to address. You've done excellent work on the database models and WebSocket setup! However, the server won't start due to a typo: please correct user.nodel.js to user.model.js in src/services/user.service.js and src/setup.js. After that, the main priorities are to connect the user routes in src/index.js to enable user creation, and to implement the missing getAll function in src/controllers/room.controller.js to fix the rooms list. Also, remember to add checks in your service files to prevent crashes when updating non-existent items. 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

return res.status(404).send({ message: 'No messages found' });
}

messageEmitter.once('message', () => res.send(messages));
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 implementation of long-polling using messageEmitter will cause the GET request to hang until a new message is created via a POST request. This prevents a new user from seeing previous messages immediately, which is a core requirement. This endpoint should send the messages array back in the response right away.

const { userService } = require('../services/user.service.js');

const getById = async (req, res) => {
const { id } = 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.

It's a common practice in REST APIs to get resource identifiers from the URL parameters (req.params) for GET requests, rather than the request body. For example, by defining a route like GET /users/:id.

};

const deleteUser = async (req, res) => {
const { id } = 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.

Similar to getting a user, deleting one is typically done via a DELETE request to a URL that includes the ID, like DELETE /users/:id. The ID would then be available in req.params.id.

return res.status(404).send({ message: 'No name was provided' });
}

const room = await roomService.update(roomId, 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 renameRoom function should verify that the room exists before attempting to update it. Currently, if an invalid roomId is passed, this call to roomService.update could crash the server. You can add a check similar to the one in your deleteRoom function to handle cases where the room is not found.

Comment on lines +54 to +59
const roomController = {
getById,
renameRoom,
createRoom,
deleteRoom,
};
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 controller is missing the getAll function, but it's being used in src/routes/room.route.js for the GET / route. This will cause the application to throw an error when that endpoint is hit. Please implement an getAll function to fetch all rooms and add it to this exported object.

Comment on lines +23 to +28
return message.update({
authorId,
text,
time,
roomId,
});
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 line will cause the application to crash if message is null (i.e., if no message with the given id is found). You need to add a check to ensure message exists before attempting to call the .update() method on it.

@@ -0,0 +1,39 @@
const { User } = require('../models/user.nodel.js');
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 typo in the file path here. It should be user.model.js, not user.nodel.js. This was mentioned in the previous review and is a critical error that will prevent the server from starting.

Comment on lines +12 to +14
const user = await getOne(id);

return user.update({ 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.

If getOne(id) returns null because the user doesn't exist, the next line user.update({ name }) will throw an error and crash the server. You need to add a check here to handle cases where the user is not found.

Comment on lines +22 to +26
const user = await getOne(id);
const arr = user.rooms;
const newArr = [...arr, roomId];

return user.update({ rooms: newArr });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to the update function, this will crash if the user with the given id is not found. You should add a check after fetching the user to ensure it exists before trying to access its properties.

@@ -0,0 +1,23 @@
const { Message } = require('./models/message.model.js');
const { Room } = require('./models/room.model.js');
const { User } = require('./models/user.nodel.js');
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 file path contains a typo. It should be ./models/user.model.js instead of user.nodel.js. This was a critical issue from the previous review, and it will cause the server to fail on startup.

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