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.

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