'use strict' const Joi = require('joi') const pluginConfig = { handlerType: 'user', docs: { get: { description: 'Get user', notes: 'Returns a user item by the id passed in the path', }, }, } /** Validator functions by request method */ const validators = { get: { params: Joi.object({ name: Joi.string().min(3).max(11), all: Joi.array(), }), }, } module.exports = { method: 'get', path: '/{name}', options: { ...pluginConfig.docs.get, tags: ['api'], auth: 'default_jwt', handler: async function (request, h) { try { const auth = { credentials: request.auth.credentials, token: request.auth.artifacts.token, } // /** Get the data for your endpoint */ // const { User } = request.models() // const all = await User.query() const { displayService } = request.services() const user = displayService.user(auth.credentials, auth.token) return { ok: true, handler: pluginConfig.handlerType, data: { name: request.params.name }, } } catch (err) { return { ok: false, handler: pluginConfig.handlerType, data: { error: err }, } } }, validate: validators.get, response: { schema: Joi.object({ ok: Joi.bool(), handler: Joi.string(), data: validators.get.params, }), failAction: 'log', }, }, }