const Joi = require('joi') const apiSchema = require('../../schemas/api') const errorSchema = require('../../schemas/errors') const params = require('../../schemas/params') const pluginConfig = { handlerType: 'notifictaion', docs: { description: 'subscribe', notes: 'Subscribe to notifications based on profile_id', }, } const validators = { params: params.profileId, } module.exports = { method: 'GET', path: '/{profile_id}/subscribe', options: { ...pluginConfig.docs, tags: ['api'], auth: false, cors: true, handler: async (request, h) => { const { profile_id } = request.params /** * Write the initial stream * !: this must remain open for notifications to work */ return request.server.methods.notify( `${profile_id}.stonk`, { profile_id, name: 'BDGRS', price: (500 + Math.floor(Math.random() * 100)).toString(), order: Math.floor(Math.random() * 2) === 1 ? 'BUY' : 'SELL', type: 'info', }, h, true, ) }, /** Validate based on validators object */ validate: { ...validators, failAction: 'log', }, }, }