Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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. handler: async request => {
  25. try {
  26. /** Get the data for your endpoint */
  27. const { User } = request.models()
  28. const all = await User.query()
  29. return {
  30. ok: true,
  31. handler: pluginConfig.handlerType,
  32. data: { name: request.params.name, all },
  33. }
  34. }
  35. catch(err) {
  36. return {
  37. ok: false,
  38. handler: pluginConfig.handlerType,
  39. data: { error: err },
  40. }
  41. }
  42. },
  43. options: {
  44. ...pluginConfig.docs.get,
  45. tags: ['api'],
  46. auth: 'default_jwt',
  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. }