'use strict' const Joi = require('joi') const pluginConfig = { handlerType: 'email', docs: { get: { description: 'checks if user email is in cache', notes: 'Checks if user email is in email cache and returns boolean', }, }, } module.exports = { method: 'POST', path: '/checkcache/', options: { ...pluginConfig.docs.get, tags: ['api'], auth: false, cors: true, handler: async function (request, h) { const { userService } = request.server.services() const userEmail = request.payload try { const emailIsInCache = await userService.checkEmailCache( userEmail, ) return { ok: true, handler: pluginConfig.handlerType, data: { emailIsInCache: emailIsInCache }, } } 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('email_res'), failAction: 'log', }, }, }