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.

online-status.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict'
  2. const Joi = require('joi')
  3. const params = require('../../schemas/params')
  4. const pluginConfig = {
  5. handlerType: 'user',
  6. docs: {
  7. get: {
  8. description: 'Get user online status',
  9. notes: 'Returns a user online status by the id passed in the path',
  10. },
  11. }
  12. }
  13. const validators = {
  14. get: {
  15. params: params.userId,
  16. }
  17. }
  18. module.exports = {
  19. method: 'get',
  20. path: '/{id}',
  21. options: {
  22. ...pluginConfig.docs.get,
  23. tags: ['api'],
  24. auth: 'default_jwt',
  25. handler: async function (request, h) {
  26. try {
  27. // TODO write userService method to return a user's status given id
  28. const { userService } = request.services()
  29. const userId = request.params.userId
  30. const status = await userService.getStatus(userId)
  31. return {
  32. ok: true,
  33. handler: pluginConfig.handlerType,
  34. data: { status: status },
  35. }
  36. } catch (err) {
  37. return {
  38. ok: false,
  39. handler: pluginConfig.handlerType,
  40. data: { error: err },
  41. }
  42. }
  43. },
  44. validate: validators.get,
  45. response: {
  46. schema: Joi.object({
  47. ok: Joi.bool(),
  48. handler: Joi.string(),
  49. data: validators.get.params,
  50. }).label('user_status_res'),
  51. failAction: 'log',
  52. },
  53. },
  54. }