|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+'use strict'
|
|
|
2
|
+
|
|
|
3
|
+const apiSchema = require('../../schemas/api')
|
|
|
4
|
+const errorSchema = require('../../schemas/errors')
|
|
|
5
|
+const profileSchema = require('../../schemas/profiles')
|
|
|
6
|
+const params = require('../../schemas/params')
|
|
|
7
|
+const Joi = require('joi')
|
|
|
8
|
+
|
|
|
9
|
+const pluginConfig = {
|
|
|
10
|
+ handlerType: 'reveal',
|
|
|
11
|
+ docs: {
|
|
|
12
|
+ description: 'Reveals part of a profile based on tag',
|
|
|
13
|
+ notes: 'returns from the Tag Associations Table',
|
|
|
14
|
+ },
|
|
|
15
|
+}
|
|
|
16
|
+
|
|
|
17
|
+const responseSchemas = {
|
|
|
18
|
+ tags: Joi.array().items(Joi.object()),
|
|
|
19
|
+ error: errorSchema.single,
|
|
|
20
|
+}
|
|
|
21
|
+
|
|
|
22
|
+const validators = {
|
|
|
23
|
+ params: params.profileId.append({ tag_id: Joi.number() }),
|
|
|
24
|
+ payload: Joi.object({
|
|
|
25
|
+ profile_id: Joi.number(),
|
|
|
26
|
+ membership_id: Joi.string().optional(),
|
|
|
27
|
+ }),
|
|
|
28
|
+}
|
|
|
29
|
+
|
|
|
30
|
+module.exports = {
|
|
|
31
|
+ method: 'POST',
|
|
|
32
|
+ path: '/{profile_id}/reveal/{tag_id}',
|
|
|
33
|
+ options: {
|
|
|
34
|
+ ...pluginConfig.docs,
|
|
|
35
|
+ tags: ['api'],
|
|
|
36
|
+ /** Protect this route with authentication? */
|
|
|
37
|
+ auth: false,
|
|
|
38
|
+ cors: true,
|
|
|
39
|
+ handler: async function (request, h) {
|
|
|
40
|
+ const { profile_id, tag_id } = request.params
|
|
|
41
|
+ const { profileService } = request.server.services()
|
|
|
42
|
+
|
|
|
43
|
+ const revealedTags = await profileService.revealProfileInfo({
|
|
|
44
|
+ profile_id,
|
|
|
45
|
+ tag_id,
|
|
|
46
|
+ is_deleted: false,
|
|
|
47
|
+ })
|
|
|
48
|
+ console.log('revealed :', revealedTags)
|
|
|
49
|
+
|
|
|
50
|
+ try {
|
|
|
51
|
+ const tag = profileService.tagLookup[tag_id]
|
|
|
52
|
+ if (!tag || tag.tag_category != 'reveal') {
|
|
|
53
|
+ throw `cannot reveal ${tag} tag`
|
|
|
54
|
+ }
|
|
|
55
|
+ return h
|
|
|
56
|
+ .response({
|
|
|
57
|
+ ok: true,
|
|
|
58
|
+ handler: pluginConfig.handlerType,
|
|
|
59
|
+ data: revealedTags,
|
|
|
60
|
+ })
|
|
|
61
|
+ .code(200)
|
|
|
62
|
+ } catch (err) {
|
|
|
63
|
+ return h
|
|
|
64
|
+ .response({
|
|
|
65
|
+ ok: false,
|
|
|
66
|
+ handler: pluginConfig.handlerType,
|
|
|
67
|
+ data: { error: `${err}` },
|
|
|
68
|
+ })
|
|
|
69
|
+ .code(409)
|
|
|
70
|
+ }
|
|
|
71
|
+ },
|
|
|
72
|
+ /** Validate based on validators object */
|
|
|
73
|
+ validate: {
|
|
|
74
|
+ ...validators,
|
|
|
75
|
+ failAction: 'log',
|
|
|
76
|
+ },
|
|
|
77
|
+
|
|
|
78
|
+ /** Validate the server response */
|
|
|
79
|
+ response: {
|
|
|
80
|
+ status: {
|
|
|
81
|
+ 200: apiSchema.single
|
|
|
82
|
+ .append({
|
|
|
83
|
+ data: responseSchemas.tags,
|
|
|
84
|
+ })
|
|
|
85
|
+ .label('reveal_res'),
|
|
|
86
|
+ 409: apiSchema.single
|
|
|
87
|
+ .append({
|
|
|
88
|
+ data: responseSchemas.error,
|
|
|
89
|
+ })
|
|
|
90
|
+ .label('error_single_res'),
|
|
|
91
|
+ },
|
|
|
92
|
+ },
|
|
|
93
|
+ },
|
|
|
94
|
+}
|