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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict'
  2. const Joi = require('joi')
  3. const pluginConfig = {
  4. handlerType: 'grouping',
  5. docs: {
  6. description: 'active memberships',
  7. notes: 'A list of groupings with active membership',
  8. },
  9. }
  10. const validators = {
  11. /** Validate the header (cookie check) */
  12. // headers: true,
  13. /** Validate the route params (/active/{thing}) */
  14. params: Joi.object({ profile_id: Joi.number() }),
  15. /** Validate the route query (/active/{thing}?limit=10&offset=10) */
  16. query: Joi.object({ type: Joi.string().lowercase().min(6).max(11) }),
  17. /** Validate the incoming payload (POST method) */
  18. // payload: true,
  19. }
  20. const responseSchemas = {
  21. groupingsList: Joi.object({
  22. grouping_id: Joi.number(),
  23. grouping_name: Joi.string(),
  24. grouping_type: Joi.string(),
  25. }),
  26. }
  27. module.exports = {
  28. method: 'GET',
  29. path: '/{profile_id}',
  30. options: {
  31. ...pluginConfig.docs,
  32. tags: ['api'],
  33. /** Protect this route with authentication? */
  34. auth: false,
  35. handler: async function (request, h) {
  36. const { membershipService } = request.services()
  37. const membershipType = request.query.type
  38. const profileId = request.params.profile_id
  39. const groupings = await membershipService.findGroupingsByProfileId(
  40. profileId,
  41. membershipType
  42. )
  43. try {
  44. return {
  45. ok: true,
  46. handler: pluginConfig.handlerType,
  47. data: groupings,
  48. }
  49. } catch (err) {
  50. return {
  51. ok: false,
  52. handler: pluginConfig.handlerType,
  53. data: { error: `${err}` },
  54. }
  55. }
  56. },
  57. /** Validate based on validators object */
  58. validate: {
  59. ...validators,
  60. failAction: 'log',
  61. },
  62. /** Validate the server response */
  63. response: {
  64. schema: Joi.object({
  65. ok: Joi.bool(),
  66. handler: Joi.string(),
  67. data: Joi.array().items(responseSchemas.groupingsList),
  68. }),
  69. },
  70. },
  71. }