You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const Joi = require('joi')
  2. const apiSchema = require('../../schemas/api')
  3. const errorSchema = require('../../schemas/errors')
  4. const params = require('../../schemas/params')
  5. const { intializeStream } = require('../../utils')
  6. const pluginConfig = {
  7. handlerType: 'notifictaion',
  8. docs: {
  9. description: 'subscribe',
  10. notes: 'Subscribe to notifications based on profile_id',
  11. },
  12. }
  13. const validators = {
  14. params: params.profileId,
  15. }
  16. module.exports = {
  17. method: 'GET',
  18. path: '/{profile_id}/subscribe',
  19. options: {
  20. ...pluginConfig.docs,
  21. tags: ['api'],
  22. auth: false,
  23. cors: true,
  24. handler: async (request, h) => {
  25. const { profile_id } = request.params
  26. /**
  27. * Write the initial stream
  28. * !: this must remain open for notifications to work
  29. */
  30. return intializeStream(`${profile_id}.stonk`, h)
  31. },
  32. /** Validate based on validators object */
  33. validate: {
  34. ...validators,
  35. failAction: 'log',
  36. },
  37. },
  38. }