Last active
September 1, 2019 07:28
-
-
Save DJanoskova/8138deb1e876e40c0a71d2cad57c6ba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Room = use('App/Models/Room'); | |
| const { broadcast } = require('../../utils/socket.utils'); | |
| async createMessage ({ params, request, response }) { | |
| const room = await Room.find(params.id); | |
| if (!room) { | |
| return response.notFound(`The room doesn't exist`) | |
| } | |
| const data = request.only(['name', 'message']); | |
| const message = await room.messages().create(data); | |
| // send the message upon new message creation | |
| // define a type for the frontend app - "room:newMessage" | |
| broadcast(room.uuid, 'room:newMessage', message); | |
| return message | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment