| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- '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}',
- handler: async request => {
- try {
- /** Get the data for your endpoint */
- const { User } = request.models()
- const all = await User.query()
-
- return {
- ok: true,
- handler: pluginConfig.handlerType,
- data: { name: request.params.name, all },
- }
- }
- catch(err) {
- return {
- ok: false,
- handler: pluginConfig.handlerType,
- data: { error: err },
- }
- }
- },
- options: {
- ...pluginConfig.docs.get,
- tags: ['api'],
- auth: 'default_jwt',
- validate: validators.get,
- response: {
- schema: Joi.object({
- ok: Joi.bool(),
- handler: Joi.string(),
- data: validators.get.params
- }),
- failAction: 'log'
- }
- }
-
- }
|