Bläddra i källkod

:sparkles: adding reveal tag endpoint

tags/0.0.2
j 3 år sedan
förälder
incheckning
aa0ac4f767

+ 2
- 0
backend/lib/plugins/profile.js Visa fil

21
 const ProfileQueueRoute = require('../routes/profile/queue')
21
 const ProfileQueueRoute = require('../routes/profile/queue')
22
 const ProfileGetRoute = require('../routes/profile/get')
22
 const ProfileGetRoute = require('../routes/profile/get')
23
 const ProfilePatchQueueRoute = require('../routes/profile/patch-queue')
23
 const ProfilePatchQueueRoute = require('../routes/profile/patch-queue')
24
+const TagRevealRoute = require('../routes/tag/reveal')
24
 
25
 
25
 module.exports = {
26
 module.exports = {
26
     name: 'profile-plugin',
27
     name: 'profile-plugin',
53
         await server.route(ProfileQueueRoute)
54
         await server.route(ProfileQueueRoute)
54
         await server.route(ProfileGetRoute)
55
         await server.route(ProfileGetRoute)
55
         await server.route(ProfilePatchQueueRoute)
56
         await server.route(ProfilePatchQueueRoute)
57
+        await server.route(TagRevealRoute)
56
     },
58
     },
57
 }
59
 }

+ 94
- 0
backend/lib/routes/tag/reveal.js Visa fil

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
+}

+ 25
- 1
backend/lib/services/profile/index.js Visa fil

11
         super(...args)
11
         super(...args)
12
         /** Scores available in the db to map against score indices*/
12
         /** Scores available in the db to map against score indices*/
13
         this.scoreLookup = {}
13
         this.scoreLookup = {}
14
-        /** Tags available in the db to map against tagg_associations*/
14
+        /** Tags available in the db to map against tag_associations*/
15
         this.tagLookup = {}
15
         this.tagLookup = {}
16
         // this.responseKeyLookup = ResponseKey.query()
16
         // this.responseKeyLookup = ResponseKey.query()
17
     }
17
     }
345
         const end = await this._latLonForZip(end_zip)
345
         const end = await this._latLonForZip(end_zip)
346
         return haversine(start, end, { unit: distanceUnit })
346
         return haversine(start, end, { unit: distanceUnit })
347
     }
347
     }
348
+
349
+    /**
350
+     * Use the db to grab tag associations
351
+     * by profile and match them to tag types
352
+     * @param {number} profileId
353
+     * @param {object}
354
+     */
355
+    async _getTagsForProfile(profileId) {
356
+        const { TagAssociation } = this.server.models()
357
+        await this._setTagLookup()
358
+        const associations = await TagAssociation.query().where(
359
+            'profile_id',
360
+            profileId,
361
+        )
362
+        return associations.map(assoc => {
363
+            const tagInfo = this.tagLookup[assoc.tag_id]
364
+            return { ...assoc, tag: tagInfo }
365
+        })
366
+    }
367
+    async revealProfileInfo(association) {
368
+        const { TagAssociation } = this.server.models()
369
+        await TagAssociation.query().insert(association)
370
+        return await this._getTagsForProfile(association.profile_id)
371
+    }
348
 }
372
 }

+ 0
- 1
frontend/src/services/chat.service.js Visa fil

121
      * @param {array} channels
121
      * @param {array} channels
122
      */
122
      */
123
     subscribe({ channels }) {
123
     subscribe({ channels }) {
124
-        console.log('subscribing to:', channels)
125
         _providerMethods.subscribe({ channels })
124
         _providerMethods.subscribe({ channels })
126
     }
125
     }
127
     /**
126
     /**

Laddar…
Avbryt
Spara