Skip to content

Instantly share code, notes, and snippets.

@DJanoskova
Last active September 1, 2019 07:28
Show Gist options
  • Select an option

  • Save DJanoskova/8138deb1e876e40c0a71d2cad57c6ba7 to your computer and use it in GitHub Desktop.

Select an option

Save DJanoskova/8138deb1e876e40c0a71d2cad57c6ba7 to your computer and use it in GitHub Desktop.
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