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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /** Protect this route with authentication? */
  27. auth: false,
  28. cors: true,
  29. handler: async function (request, h) {
  30. const { profile_id } = request.params
  31. const { profileService } = request.server.services()
  32. const res = {
  33. ok: true,
  34. handler: pluginConfig.handlerType,
  35. data: null,
  36. }
  37. res.data = await profileService.getProfile(profile_id)
  38. try {
  39. return h.response(res).code(200)
  40. } catch (err) {
  41. return h
  42. .response({
  43. ok: false,
  44. handler: pluginConfig.handlerType,
  45. data: { error: `${err}` },
  46. })
  47. .code(409)
  48. }
  49. },
  50. /** Validate based on validators object */
  51. validate: {
  52. ...validators,
  53. failAction: 'log',
  54. },
  55. /** Validate the server response */
  56. response: {
  57. status: {
  58. 200: apiSchema.single
  59. .append({
  60. data: responseSchemas.profile,
  61. })
  62. .label('profile_single_res'),
  63. 409: apiSchema.single
  64. .append({
  65. data: responseSchemas.error,
  66. })
  67. .label('error_single_res'),
  68. },
  69. },
  70. },
  71. }