Registeration controller for users with websockets

Hello,
I am Viera and need help in WebSockets Adonis js
I want to create a WebSocket controller that registers users because I want realtime activity in my application but I don’t know where to start from.
Even when people create orders they should come to the admin dashboard in real-time.
Thank you.

Welcome @viera,

start read the docs http://adonisjs.com/docs/4.1/websocket.

What will your client side? adonis, react, vue, …

1 Like

lt is Vue js

1 Like

nice. Follow the documentation, hope will help.

if get any error, post here. :slightly_smiling_face:

1 Like

Hey i have have orderitem contoller of http but l want to transform it into websocket controller.
Please help.

‘use strict’
const Product = use(‘App/Models/Product’)
const User = use(‘App/Models/User’)
const Order = use(‘App/Models/Order’)
const image = (‘https://hooks.slack.com/services/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’)
const axios = require(‘axios’)
const Database = use(‘Database’)

class OrderController {

async post({ request, auth, response }) {

try {


 const isLoggedIn = await auth.check()
 
 if (isLoggedIn) {
    const user = await auth.getUser()
    
    const order = request.only(['user_id', 'status','order_type','grand_total','paid'])

   if (order.user_id == user.id) {

        const orders = await Order.create(order)
        orders.save()

        await User
        .query()
        .where('email', user.email)
        .increment('order_count', 1)

        response.status(201).json({
          message: "Order stored",

          
          request: {
            type: "POST",
            url: "http://localhost:3333/orders/"
          }
        })
        axios({
          method: 'post',
          url: image,

          data: {
            text: 'New Order', 
            text:order  
          }
        })
    }
      else{
        response.forbidden(400).json({
          message: "UnAuthorized User",
        })
      }
    }
    else{
      response.status(400).json({
        message: "Login first",
      })
  }

} catch (error) {
  response.status(400).json({
    error:error,
    message: "Error Occured",
  })
}

}
}

Sorry order controller