| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- const Joi = require('joi')
- const apiSchema = require('../../schemas/api')
- const errorSchema = require('../../schemas/errors')
- const params = require('../../schemas/params')
-
- const { intializeStream } = require('../../utils')
-
- 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 intializeStream(`${profile_id}.stonk`, h)
- },
-
- /** Validate based on validators object */
- validate: {
- ...validators,
- failAction: 'log',
- },
- },
- }
|