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.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }
  13. const responseSchemas = {
  14. profile: profileSchema.single,
  15. error: errorSchema.single,
  16. }
  17. const validators = {
  18. params: params.profileId,
  19. }
  20. module.exports = {
  21. method: 'GET',
  22. path: '/{profile_id}',
  23. options: {
  24. ...pluginConfig.docs,
  25. tags: ['api'],
  26. auth: 'default_jwt',
  27. cors: true,
  28. handler: async function (request, h) {
  29. const { profile_id } = request.params
  30. const { profileService } = request.server.services()
  31. const res = {
  32. ok: true,
  33. handler: pluginConfig.handlerType,
  34. data: null,
  35. }
  36. res.data = await profileService.getProfile(profile_id)
  37. try {
  38. return h.response(res).code(200)
  39. } catch (err) {
  40. return h
  41. .response({
  42. ok: false,
  43. handler: pluginConfig.handlerType,
  44. data: { error: `${err}` },
  45. })
  46. .code(409)
  47. }
  48. },
  49. /** Validate based on validators object */
  50. validate: {
  51. ...validators,
  52. failAction: 'log',
  53. },
  54. /** Validate the server response */
  55. response: {
  56. status: {
  57. 200: apiSchema.single
  58. .append({
  59. data: responseSchemas.profile,
  60. })
  61. .label('profile_single_res'),
  62. 409: apiSchema.single
  63. .append({
  64. data: responseSchemas.error,
  65. })
  66. .label('error_single_res'),
  67. },
  68. },
  69. },
  70. }