'use strict' const Joi = require('joi') const apiSchema = require('../../schemas/api') const errorSchema = require('../../schemas/errors') const profileSchema = require('../../schemas/profiles') const params = require('../../schemas/params') const pluginConfig = { handlerType: 'profile', docs: { description: 'Returns a single profile with tags', notes: 'returns from the Profiles Table', }, } const responseSchemas = { profile: profileSchema.single, error: errorSchema.single, } const validators = { params: params.profileId, } module.exports = { method: 'GET', path: '/{profile_id}', options: { ...pluginConfig.docs, tags: ['api'], /** Protect this route with authentication? */ auth: false, cors: true, handler: async function (request, h) { const { profile_id } = request.params const { profileService } = request.server.services() const res = { ok: true, handler: pluginConfig.handlerType, data: null, } res.data = await profileService.getProfile(profile_id) try { return h.response(res).code(200) } catch (err) { return h .response({ ok: false, handler: pluginConfig.handlerType, data: { error: `${err}` }, }) .code(409) } }, /** Validate based on validators object */ validate: { ...validators, failAction: 'log', }, /** Validate the server response */ response: { status: { 200: apiSchema.single .append({ data: responseSchemas.profile, }) .label('profile_single_res'), 409: apiSchema.single .append({ data: responseSchemas.error, }) .label('error_single_res'), }, }, }, }