您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

current.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. }
  47. catch(err) {
  48. return {
  49. ok: false,
  50. handler: pluginConfig.handlerType,
  51. data: { error: err },
  52. }
  53. }
  54. },
  55. validate: validators.get,
  56. response: {
  57. schema: Joi.object({
  58. ok: Joi.bool(),
  59. handler: Joi.string(),
  60. data: validators.get.params
  61. }),
  62. failAction: 'log'
  63. }
  64. }
  65. }