選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

online-status.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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}/status',
  21. options: {
  22. ...pluginConfig.docs.get,
  23. tags: ['api'],
  24. auth: 'default_jwt',
  25. handler: async function (request, h) {
  26. try {
  27. const { userService } = request.services()
  28. const userId = request.params.userId
  29. const status = await userService.getStatus(userId, request.server.app.loggedInUsers)
  30. return {
  31. ok: true,
  32. handler: pluginConfig.handlerType,
  33. data: { status: status },
  34. }
  35. } catch (err) {
  36. return {
  37. ok: false,
  38. handler: pluginConfig.handlerType,
  39. data: { error: err },
  40. }
  41. }
  42. },
  43. validate: validators.get,
  44. response: {
  45. schema: Joi.object({
  46. ok: Joi.bool(),
  47. handler: Joi.string(),
  48. data: validators.get.params,
  49. }).label('user_status_res'),
  50. failAction: 'log',
  51. },
  52. },
  53. }