Slået op d.

Create a note in cam area (/:roomId/message) [POST demand]

Create a note in cam area (/:roomId/message) [POST demand]

A very important factor to notice let me reveal userIds, sort comes from req.body while userId definitely being aliased as chatInitiatorId comes from req thanks to our very own decode middleware.

Any time you bear in mind, we affixed app.use(“/room”, decode, chatRoomRouter); within our server/index.js file. This means this route /room/initiate try authenticated. Therefore const < userId:>= req; will be the id regarding the recent consumer logged around.

We simply call our very own initiateChat means from ChatRoomModel and move it allUserIds, kind, chatInitiator . Whatever lead arrives we just go it towards consumer.

However before we develop a message we must establish an unit for the chatmessages . Very let us do that initially. In your models folder produce a brand new document labeled as ChatMessage.js and incorporate the subsequent material to it:

  • There is a MESSAGE_TYPES object which has one sort called text
  • We have been identifying our outline for chatmessage and readByRecipient
  • After that the audience is creating every static method for createPostInChatRoom

I understand that is many contents, but just carry beside me. Why don’t we just write the controller for any course that produces this content.

For all the route identified in our routes/chatRoom.js API (‘/:roomId/message’, chatRoom.postMessage) let’s visit their operator in controllers/chatRoom.js and define it:

  • $complement
  • $last
  • $addToSet
  • $lookup
  • $unwind
  • $team

See discussion for a speak area by it’s id [Get demand]

For the path .get(‘/:roomId’, chatRoom.getConversationByRoomId) in routes/chatRoom.js open the controller for the file controllers/chatRoom.js and add listed here material towards the talk room:

Læs mere Create a note in cam area (/:roomId/message) [POST demand]