'use strict' const Joi = require('joi') const pluginConfig = { handlerType: 'email', docs: { get: { description: 'sends confirmation email', notes: 'Stores the email in memory in a hash and sends confirmation email for signup', }, }, } module.exports = { method: 'POST', path: '/sendemail/', options: { ...pluginConfig.docs.get, tags: ['api'], auth: false, cors: true, handler: async function (request, h) { const { userService } = request.server.services() const userEmail = request.payload.email try { const emailSent = await userService.emailSent(userEmail) return { ok: true, handler: pluginConfig.handlerType, data: { emailSentSuccessfully: emailSent.wasSuccessfull }, } } 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', }, }, }