| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 'use strict'
-
- const Joi = require('joi')
- const apiSchema = require('../../schemas/api')
- const surveyResponseSchema = require('../../schemas/responses')
-
- const pluginConfig = {
- handlerType: 'survey',
- docs: {
- description: 'Get survey questions',
- notes: 'Returns a list of all possible survey questions in the form of response_keys',
- },
- }
-
- /** Validator functions by request method */
- const validators = {
- /** Validate the header (cookie check) */
- // headers: true,
- /** Validate the route params (/active/{thing}) */
- // params: true,
- /** Validate the route query (/active/{thing}?limit=10&offset=10) */
- // query: true,
- /** Validate the incoming payload (POST method) */
- // payload: true,
- }
- const responseSchemas = {
- response: surveyResponseSchema.keys,
- }
-
- module.exports = {
- method: 'GET',
- path: '/questions',
- options: {
- ...pluginConfig.docs,
- tags: ['api'],
- /** Protect this route with authentication? */
- auth: false,
- cors: true,
- handler: async function (request, h) {
- const { responseService } = request.services()
- const responseKeys = await responseService.getResponseKeys()
- try {
- return {
- ok: true,
- handler: pluginConfig.handlerType,
- data: responseKeys,
- }
- } catch (err) {
- return {
- ok: false,
- handler: pluginConfig.handlerType,
- data: { error: err },
- }
- }
- },
-
- /** Validate based on validators object */
- validate: { ...validators, failAction: 'log' },
-
- /** Validate the server response */
- response: {
- schema: apiSchema.single
- .append({
- data: responseSchemas.response,
- })
- .label('question_list_res'),
- failAction: 'log',
- },
- },
- }
|