| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 'use strict'
-
- 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? */
- // TODO: change this once sessionToken is passed in headers
- auth: false,
- // auth: 'default_jwt',
- 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'),
- },
- },
- },
- }
|