-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for chat #2
base: develop
Are you sure you want to change the base?
Conversation
Update features, environment variables, and screenshots.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 }) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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', | ||
}, | ||
}) |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use chatRoomId
only
No description provided.