| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 'use strict'
-
- const Joi = require('joi')
-
- 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 = {
- responseKeysList: Joi.object({
- response_key_id: Joi.number().required(),
- profile_id: Joi.number().required(),
- val: Joi.string().required(),
- }),
- }
-
- 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: Joi.object({
- ok: Joi.bool(),
- handler: Joi.string(),
- data: Joi.array().items(responseSchemas.responseKeysList),
- }),
- failAction: 'log',
- },
- },
- }
|