Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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