Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 pluginConfig = {
  6. handlerType: 'notifictaion',
  7. docs: {
  8. description: 'subscribe',
  9. notes: 'Subscribe to notifications based on profile_id',
  10. },
  11. }
  12. const validators = {
  13. params: params.profileId,
  14. }
  15. module.exports = {
  16. method: 'GET',
  17. path: '/{profile_id}/subscribe',
  18. options: {
  19. ...pluginConfig.docs,
  20. tags: ['api'],
  21. auth: false,
  22. cors: true,
  23. handler: async (request, h) => {
  24. const { profile_id } = request.params
  25. /**
  26. * Write the initial stream
  27. * !: this must remain open for notifications to work
  28. */
  29. return request.server.methods.notify(
  30. `${profile_id}.stonk`,
  31. {
  32. profile_id,
  33. name: 'BDGRS',
  34. price: (500 + Math.floor(Math.random() * 100)).toString(),
  35. order: Math.floor(Math.random() * 2) === 1 ? 'BUY' : 'SELL',
  36. type: 'info',
  37. },
  38. h,
  39. true,
  40. )
  41. },
  42. /** Validate based on validators object */
  43. validate: {
  44. ...validators,
  45. failAction: 'log',
  46. },
  47. },
  48. }