Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'user',
  5. docs: {
  6. get: {
  7. description: 'Get user',
  8. notes: 'Returns a user item by the id passed in the path',
  9. },
  10. },
  11. }
  12. /** Validator functions by request method */
  13. const validators = {
  14. get: {
  15. params: Joi.object({
  16. name: Joi.string().min(3).max(11),
  17. all: Joi.array(),
  18. }),
  19. },
  20. }
  21. module.exports = {
  22. method: 'get',
  23. path: '/{name}',
  24. options: {
  25. ...pluginConfig.docs.get,
  26. tags: ['api'],
  27. auth: 'default_jwt',
  28. handler: async function (request, h) {
  29. console.log('current')
  30. console.log(request)
  31. try {
  32. const auth = {
  33. credentials: request.auth.credentials,
  34. token: request.auth.artifacts.token,
  35. }
  36. // /** Get the data for your endpoint */
  37. // const { User } = request.models()
  38. // const all = await User.query()
  39. const { displayService } = request.services()
  40. const user = displayService.user(auth.credentials, auth.token)
  41. return {
  42. ok: true,
  43. handler: pluginConfig.handlerType,
  44. data: { name: request.params.name },
  45. }
  46. } catch (err) {
  47. return {
  48. ok: false,
  49. handler: pluginConfig.handlerType,
  50. data: { error: err },
  51. }
  52. }
  53. },
  54. validate: validators.get,
  55. response: {
  56. schema: Joi.object({
  57. ok: Joi.bool(),
  58. handler: Joi.string(),
  59. data: validators.get.params,
  60. }),
  61. failAction: 'log',
  62. },
  63. },
  64. }