You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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