|
|
@@ -1,88 +0,0 @@
|
|
1
|
|
-'use strict'
|
|
2
|
|
-
|
|
3
|
|
-const Joi = require('joi')
|
|
4
|
|
-const errorSchema = require('../../schemas/errors')
|
|
5
|
|
-const profileSchema = require('../../schemas/profiles')
|
|
6
|
|
-const params = require('../../schemas/params')
|
|
7
|
|
-
|
|
8
|
|
-const pluginConfig = {
|
|
9
|
|
- handlerType: 'user',
|
|
10
|
|
- docs: {
|
|
11
|
|
- description: 'profiles',
|
|
12
|
|
- notes: 'A list of profiles associated with this user',
|
|
13
|
|
- },
|
|
14
|
|
-}
|
|
15
|
|
-
|
|
16
|
|
-const validators = {
|
|
17
|
|
- /** Validate the header (cookie check) */
|
|
18
|
|
- // headers: true,
|
|
19
|
|
-
|
|
20
|
|
- /** Validate the route params (/active/{thing}) */
|
|
21
|
|
- params: params.userId,
|
|
22
|
|
-
|
|
23
|
|
- /** Validate the route query (/active/{thing}?limit=10&offset=10) */
|
|
24
|
|
- // query: true,
|
|
25
|
|
- /** Validate the incoming payload (POST method) */
|
|
26
|
|
- // payload: true,
|
|
27
|
|
-}
|
|
28
|
|
-
|
|
29
|
|
-const responseSchemas = {
|
|
30
|
|
- profilesList: profileSchema.list,
|
|
31
|
|
- error: errorSchema.single,
|
|
32
|
|
-}
|
|
33
|
|
-
|
|
34
|
|
-module.exports = {
|
|
35
|
|
- method: 'GET',
|
|
36
|
|
- path: '/{user_id}/profiles',
|
|
37
|
|
- options: {
|
|
38
|
|
- ...pluginConfig.docs,
|
|
39
|
|
- tags: ['api'],
|
|
40
|
|
- auth: 'default_jwt',
|
|
41
|
|
- cors: true,
|
|
42
|
|
- handler: async function (request, h) {
|
|
43
|
|
- const { userService, profileService } = request.server.services()
|
|
44
|
|
- const userId = request.params.user_id
|
|
45
|
|
- const user = await userService.findById(userId)
|
|
46
|
|
- const type = user.is_poster == 1 ? 'poster' : 'seeker'
|
|
47
|
|
- const profiles = await profileService.getCompleteProfilesFor(
|
|
48
|
|
- userId,
|
|
49
|
|
- type,
|
|
50
|
|
- )
|
|
51
|
|
- try {
|
|
52
|
|
- return {
|
|
53
|
|
- ok: true,
|
|
54
|
|
- handler: pluginConfig.handlerType,
|
|
55
|
|
- data: profiles,
|
|
56
|
|
- }
|
|
57
|
|
- } catch (err) {
|
|
58
|
|
- return {
|
|
59
|
|
- ok: false,
|
|
60
|
|
- handler: pluginConfig.handlerType,
|
|
61
|
|
- data: { error: `${err}` },
|
|
62
|
|
- }
|
|
63
|
|
- }
|
|
64
|
|
- },
|
|
65
|
|
-
|
|
66
|
|
- /** Validate based on validators object */
|
|
67
|
|
- validate: {
|
|
68
|
|
- ...validators,
|
|
69
|
|
- failAction: 'log',
|
|
70
|
|
- },
|
|
71
|
|
-
|
|
72
|
|
- /** Validate the server response */
|
|
73
|
|
- response: {
|
|
74
|
|
- status: {
|
|
75
|
|
- 200: Joi.object({
|
|
76
|
|
- ok: Joi.bool(),
|
|
77
|
|
- handler: Joi.string(),
|
|
78
|
|
- data: responseSchemas.profilesList,
|
|
79
|
|
- }).label('list_profiles_res'),
|
|
80
|
|
- 500: Joi.object({
|
|
81
|
|
- ok: Joi.bool(),
|
|
82
|
|
- handler: Joi.string(),
|
|
83
|
|
- data: responseSchemas.error,
|
|
84
|
|
- }).label('error_single_res'),
|
|
85
|
|
- },
|
|
86
|
|
- },
|
|
87
|
|
- },
|
|
88
|
|
-}
|