Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

current.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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: '/user/{name}',
  24. // auth: 'jwt',
  25. handler: async request => {
  26. try {
  27. /** Get the data for your endpoint */
  28. const { User } = request.models()
  29. const all = await User.query()
  30. return {
  31. ok: true,
  32. handler: pluginConfig.handlerType,
  33. data: { name: request.params.name, all },
  34. }
  35. }
  36. catch(err) {
  37. return {
  38. ok: false,
  39. handler: pluginConfig.handlerType,
  40. data: { error: err },
  41. }
  42. }
  43. },
  44. options: {
  45. ...pluginConfig.docs.get,
  46. tags: ['api'],
  47. validate: validators.get,
  48. response: {
  49. schema: Joi.object({
  50. ok: Joi.bool(),
  51. handler: Joi.string(),
  52. data: validators.get.params
  53. }),
  54. failAction: 'log'
  55. }
  56. }
  57. }