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ů.

get.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict'
  2. const apiSchema = require('../../schemas/api')
  3. const errorSchema = require('../../schemas/errors')
  4. const profileSchema = require('../../schemas/profiles')
  5. const params = require('../../schemas/params')
  6. const pluginConfig = {
  7. handlerType: 'profile',
  8. docs: {
  9. description: 'Returns a single profile with tags',
  10. notes: 'returns from the Profiles Table',
  11. },
  12. opts: {
  13. tags: ['api'],
  14. auth:
  15. process.env.USE_AUTH != 'true'
  16. ? false
  17. : { strategy: 'default_jwt' },
  18. cors: true,
  19. },
  20. }
  21. const responseSchemas = {
  22. profile: profileSchema.single,
  23. error: errorSchema.single,
  24. }
  25. const validators = {
  26. params: params.profileId,
  27. }
  28. module.exports = {
  29. method: 'GET',
  30. path: '/{profile_id}',
  31. options: {
  32. ...pluginConfig.docs,
  33. ...pluginConfig.opts,
  34. handler: async function (request, h) {
  35. const { profile_id } = request.params
  36. const { profileService } = request.server.services()
  37. const res = {
  38. ok: true,
  39. handler: pluginConfig.handlerType,
  40. data: null,
  41. }
  42. res.data = await profileService.getProfile(profile_id)
  43. try {
  44. return h.response(res).code(200)
  45. } catch (err) {
  46. return h
  47. .response({
  48. ok: false,
  49. handler: pluginConfig.handlerType,
  50. data: { error: `${err}` },
  51. })
  52. .code(409)
  53. }
  54. },
  55. /** Validate based on validators object */
  56. validate: {
  57. ...validators,
  58. failAction: 'log',
  59. },
  60. /** Validate the server response */
  61. response: {
  62. status: {
  63. 200: apiSchema.single
  64. .append({
  65. data: responseSchemas.profile,
  66. })
  67. .label('profile_single_res'),
  68. 409: apiSchema.single
  69. .append({
  70. data: responseSchemas.error,
  71. })
  72. .label('error_single_res'),
  73. },
  74. },
  75. },
  76. }