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ů.

responses.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict'
  2. const Joi = require('joi')
  3. const apiSchema = require('../../schemas/api')
  4. const surveyResponseSchema = require('../../schemas/responses')
  5. const params = require('../../schemas/params')
  6. const pluginConfig = {
  7. handlerType: 'survey',
  8. docs: {
  9. description: 'Get responses to questions',
  10. notes: 'Returns a list of all survey responses for a user',
  11. },
  12. opts: {
  13. tags: ['api'],
  14. auth: { strategy: 'default_jwt' },
  15. cors: true,
  16. },
  17. }
  18. /** Validator functions by request method */
  19. const validators = {
  20. /** Validate the header (cookie check) */
  21. // headers: true,
  22. /** Validate the route params (/active/{thing}) */
  23. params: params.userId,
  24. /** Validate the route query (/active/{thing}?limit=10&offset=10) */
  25. // query: true,
  26. /** Validate the incoming payload (POST method) */
  27. // payload: true,
  28. }
  29. const responseSchemas = {
  30. response: surveyResponseSchema.keys,
  31. }
  32. module.exports = {
  33. method: 'GET',
  34. path: '/questions',
  35. options: {
  36. ...pluginConfig.docs,
  37. ...pluginConfig.opts,
  38. handler: async function (request, h) {
  39. const { responseService } = request.services()
  40. const responseKeys = await responseService.getResponseKeys()
  41. try {
  42. return {
  43. ok: true,
  44. handler: pluginConfig.handlerType,
  45. data: responseKeys,
  46. }
  47. } catch (err) {
  48. return {
  49. ok: false,
  50. handler: pluginConfig.handlerType,
  51. data: { error: err },
  52. }
  53. }
  54. },
  55. /** Validate based on validators object */
  56. validate: { ...validators, failAction: 'log' },
  57. /** Validate the server response */
  58. response: {
  59. schema: apiSchema.single
  60. .append({
  61. data: responseSchemas.response,
  62. })
  63. .label('response_list_res'),
  64. failAction: 'log',
  65. },
  66. },
  67. }