| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 'use strict'
-
- const Joi = require('joi')
- const params = require('../../schemas/params')
-
- 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: params.userName,
- },
- }
-
- 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,
- }).label('user_name_res'),
- failAction: 'log',
- },
- },
- }
|