'use strict' const Joi = require('joi') const pluginConfig = { handlerType: 'email', docs: { get: { description: 'Fetches User Data by Email', notes: 'Grabs the User Data by Email for use in survey validation', }, }, } module.exports = { method: 'GET', path: '/fetchbymail/{email}', options: { ...pluginConfig.docs.get, tags: ['api'], auth: 'default_jwt', cors: true, handler: async function (request, h) { const email = request.params.email const { userService } = request.server.services() const data = await userService.findByUserEmail(email) try { return { ok: true, handler: pluginConfig.handlerType, data: data, } } catch (err) { return { ok: false, handler: pluginConfig.handlerType, data: { error: err, }, } } }, validate: { failAction: 'log', }, response: { schema: Joi.object({ ok: Joi.bool(), handler: Joi.string(), data: Joi.object(), }).label('fetchbymail'), failAction: 'log', }, }, }