Skip to content

Add support for chat#2

Open
Singh233 wants to merge 13 commits intodevelopfrom
feature/messaging
Open

Add support for chat#2
Singh233 wants to merge 13 commits intodevelopfrom
feature/messaging

Conversation

@Singh233
Copy link
Owner

@Singh233 Singh233 commented May 1, 2023

No description provided.

@Singh233 Singh233 requested a review from Anshu-rai89 May 1, 2023 07:20
Copy link
Collaborator

@Anshu-rai89 Anshu-rai89 left a comment

Choose a reason for hiding this comment

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

Lets address all these comments as well optimizations

const router = express.Router();
const chatApi = require('../../../controllers/api/v1/chat_api');

router.get('/:type/:sender/:receiver', chatApi.createChatRoom);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add endpoint bluprint for all api endpoint

let chatRoomId = data.sender + data.receiver;
let reverseChatRoomId = data.receiver + data.sender;

if (data.type == 'global') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

move this logic to saprate function. Move string to variable. Make it group and private


module.exports.createChatRoom = async function (req, res) {
try {
const data = req.params;
Copy link
Collaborator

Choose a reason for hiding this comment

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

add validation

module.exports.createChatRoom = async function (req, res) {
try {
const data = req.params;
console.log(data);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove logs

.exec(function (err, chatRoom) {
if (err) {
console.log('Error in finding chat room', err);
return res.status(500).json({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add error handling through middleware and error class

try {
const data = req.params;
console.log(data);
let chatRoomId = data.sender + data.receiver;
Copy link
Collaborator

Choose a reason for hiding this comment

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

use const



// if the chat room already exists then return the chat room
ChatRoom.findOne({ chatRoomId: data.receiver + data.sender })
Copy link
Collaborator

Choose a reason for hiding this comment

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

use async await here.

});
} else {
// create a new chat room
ChatRoom.create(
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this lookup handle this at the time of creating a freind

populate: {
path: 'sender',
},
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

use select here

// create a new chat room
ChatRoom.create(
{
chatRoomId: 'global',
Copy link
Collaborator

Choose a reason for hiding this comment

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

use chatRoomId only

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