Procházet zdrojové kódy

:sparkles: new reveal api endpoint | send messages on reveal tag creation | create tags in chat

tags/0.0.3^2
j před 3 roky
rodič
revize
87a928002e

+ 26
- 0
backend/db/data-generator/mock.js Zobrazit soubor

@@ -38,6 +38,18 @@ module.exports = {
38 38
             tag_description: 'urgency',
39 39
             is_active: true,
40 40
         },
41
+        {
42
+            tag_id: 7,
43
+            tag_category: 'reveal',
44
+            tag_description: 'user_name',
45
+            is_active: true,
46
+        },
47
+        {
48
+            tag_id: 8,
49
+            tag_category: 'reveal',
50
+            tag_description: 'user_email',
51
+            is_active: true,
52
+        },
41 53
     ],
42 54
     tag_associations: [
43 55
         {
@@ -89,6 +101,20 @@ module.exports = {
89 101
             tag_id: 5,
90 102
             is_deleted: false,
91 103
         },
104
+        {
105
+            tag_association_id: 8,
106
+            profile_id: 41,
107
+            grouping_id: 1,
108
+            tag_id: 4,
109
+            is_deleted: false,
110
+        },
111
+        {
112
+            tag_association_id: 9,
113
+            profile_id: 41,
114
+            grouping_id: 1,
115
+            tag_id: 5,
116
+            is_deleted: false,
117
+        },
92 118
     ],
93 119
     response_keys: [
94 120
         {

+ 2
- 0
backend/lib/plugins/membership.js Zobrazit soubor

@@ -9,6 +9,7 @@ const MembershipService = require('../services/membership')
9 9
 const MembershipJoinRoute = require('../routes/membership/join')
10 10
 const MembershipLeaveRoute = require('../routes/membership/leave')
11 11
 const MembershipActiveRoute = require('../routes/membership/active')
12
+const MembershipRevealRoute = require('../routes/membership/reveal')
12 13
 
13 14
 module.exports = {
14 15
     name: 'membership-plugin',
@@ -29,5 +30,6 @@ module.exports = {
29 30
         await server.route(MembershipJoinRoute)
30 31
         await server.route(MembershipLeaveRoute)
31 32
         await server.route(MembershipActiveRoute)
33
+        await server.route(MembershipRevealRoute)
32 34
     },
33 35
 }

+ 0
- 1
backend/lib/routes/membership/active.js Zobrazit soubor

@@ -74,7 +74,6 @@ module.exports = {
74 74
             let memberships = await membershipService.findMemberships(
75 75
                 groupings.map(grouping => grouping.grouping_id),
76 76
             )
77
-            // console.log('groupings :>> ', memberships)
78 77
 
79 78
             /**
80 79
              * Heavily process the result by storing just a profile_id

+ 104
- 0
backend/lib/routes/membership/reveal.js Zobrazit soubor

@@ -0,0 +1,104 @@
1
+const Joi = require('joi')
2
+
3
+const apiSchema = require('../../schemas/api')
4
+const errorSchema = require('../../schemas/errors')
5
+
6
+const pluginConfig = {
7
+    handlerType: 'reveal',
8
+    docs: {
9
+        description: 'reveal',
10
+        notes: 'Reveal profile information to a grouping by membership',
11
+    },
12
+}
13
+
14
+const validators = {
15
+    params: Joi.object({ grouping_id: Joi.number() }),
16
+    query: Joi.object({ profile_id: Joi.number(), tag_id: Joi.number() }),
17
+}
18
+
19
+const responseSchemas = {
20
+    response: Joi.object({
21
+        tags: Joi.array().items(),
22
+    }),
23
+    error: errorSchema.single,
24
+}
25
+module.exports = {
26
+    method: 'POST',
27
+    path: '/{grouping_id}/reveal',
28
+    options: {
29
+        ...pluginConfig.docs,
30
+        tags: ['api'],
31
+        auth: false,
32
+        cors: true,
33
+        handler: async function (request, h) {
34
+            const { membershipService, profileService } =
35
+                request.server.services()
36
+            const grouping_id = request.params.grouping_id
37
+            const { profile_id, tag_id } = request.query
38
+            try {
39
+                const tags = await profileService.revealProfileInfo({
40
+                    profile_id,
41
+                    grouping_id,
42
+                    tag_id,
43
+                    is_deleted: false,
44
+                })
45
+
46
+                // Notify both profiles that information has been revealed
47
+                const memberships = await membershipService.findMemberships([
48
+                    grouping_id,
49
+                ])
50
+                const idsInGroup = memberships.map(
51
+                    membership => membership.profile_id,
52
+                )
53
+                idsInGroup.forEach(profile_id => {
54
+                    request.server.methods.notify(
55
+                        `${profile_id}.stonk`,
56
+                        {
57
+                            name: 'REVEALED INFO',
58
+                            tag: tag_id,
59
+                            type: 'info',
60
+                        },
61
+                        h,
62
+                    )
63
+                })
64
+                return h
65
+                    .response({
66
+                        ok: true,
67
+                        handler: pluginConfig.handlerType,
68
+                        data: { tags },
69
+                    })
70
+                    .code(200)
71
+            } catch (err) {
72
+                return h
73
+                    .response({
74
+                        ok: false,
75
+                        handler: pluginConfig.handlerType,
76
+                        data: { error: `${err}` },
77
+                    })
78
+                    .code(409)
79
+            }
80
+        },
81
+
82
+        /** Validate based on validators object */
83
+        validate: {
84
+            ...validators,
85
+            failAction: 'log',
86
+        },
87
+
88
+        /** Validate the server response */
89
+        response: {
90
+            status: {
91
+                200: apiSchema.single
92
+                    .append({
93
+                        data: responseSchemas.response,
94
+                    })
95
+                    .label('reveal_res'),
96
+                409: apiSchema.single
97
+                    .append({
98
+                        data: responseSchemas.error,
99
+                    })
100
+                    .label('error_single_res'),
101
+            },
102
+        },
103
+    },
104
+}

+ 1
- 0
backend/lib/services/profile/index.js Zobrazit soubor

@@ -374,6 +374,7 @@ module.exports = class ProfileService extends Schmervice.Service {
374 374
     async revealProfileInfo(association) {
375 375
         const { TagAssociation } = this.server.models()
376 376
         await TagAssociation.query().insert(association)
377
+
377 378
         return await this.getTagsFor(association.profile_id)
378 379
     }
379 380
 }

+ 1
- 1
backend/lib/services/profile/profiler.js Zobrazit soubor

@@ -14,7 +14,7 @@ class CompleteProfile {
14 14
         this.user_email = profile.user.user_email
15 15
         this.responses = []
16 16
         this.user_type = type
17
-        this.tags = profile.tags.filter(t => t.category != 'reveal')
17
+        this.tags = profile.tags.filter(t => t.tag_category != 'reveal')
18 18
 
19 19
         // TODO: generalize this for multiple images, and languages
20 20
         this.profile_description = ''

+ 1
- 0
frontend/src/entities/card/card.js Zobrazit soubor

@@ -97,6 +97,7 @@ class Card {
97 97
 
98 98
         this.images = []
99 99
         this.tags = []
100
+        this.reveal = {}
100 101
 
101 102
         this.summary = new SummaryGroup()
102 103
 

+ 21
- 0
frontend/src/entities/grouping/grouping.js Zobrazit soubor

@@ -2,6 +2,7 @@
2 2
 
3 3
 import { _baseRecord } from '../index.js'
4 4
 import { groupingSchema } from './grouping.schema.js'
5
+// import { revealProfileInfo } from '../../services/profile.service.js'
5 6
 
6 7
 /** Class representing a grouping */
7 8
 class Grouping extends _baseRecord {
@@ -22,6 +23,26 @@ class Grouping extends _baseRecord {
22 23
 
23 24
         return this
24 25
     }
26
+    get revealed() {
27
+        const revealed = {}
28
+        this.tags
29
+            .filter(assoc => assoc.tag.tag_category == 'reveal')
30
+            .forEach(assoc => {
31
+                if (!revealed[assoc.profile_id]) {
32
+                    revealed[assoc.profile_id] = []
33
+                }
34
+                revealed[assoc.profile_id].push({
35
+                    description: assoc.tag.tag_description,
36
+                })
37
+            })
38
+        return revealed
39
+    }
40
+    get participants() {
41
+        return [this.profile.profile_id]
42
+    }
43
+    async reveal(profileId, tagId) {
44
+        // return await revealProfileInfo(profileId, tagId)
45
+    }
25 46
     /**
26 47
      * validate this record
27 48
      * @return {boolean} is it valid or not?

+ 21
- 4
frontend/src/services/grouping.service.js Zobrazit soubor

@@ -15,12 +15,17 @@ const fetchMembershipsByProfileId = async profileId => {
15 15
         memberships = await db.get(`/membership/${profileId}`)
16 16
         for (let membership of memberships) {
17 17
             const grouping = new Grouping(membership)
18
-            grouping.tags = await db.get(
19
-                `/profile/${profileId}/tags/${grouping.grouping_id}`,
20
-            )
21 18
             if (grouping.isValid()) {
22 19
                 // Reformat incoming profile data into Profile entity
23 20
                 grouping.profile = new Profile(grouping.profile)
21
+                const targetTags = await db.get(
22
+                    `/profile/${grouping.profile.profile_id}/tags/${grouping.grouping_id}`,
23
+                )
24
+                const profileTags = await db.get(
25
+                    `/profile/${profileId}/tags/${grouping.grouping_id}`,
26
+                )
27
+                grouping.tags = [...targetTags, ...profileTags]
28
+                console.log('grouping.tags :>> ', grouping.tags)
24 29
                 validGroupingInstances.push(grouping)
25 30
             }
26 31
         }
@@ -54,4 +59,16 @@ const postMembershipByProfileId = async ({
54 59
     )
55 60
     return { membershipMatch, groupingName: membership.grouping_name }
56 61
 }
57
-export { fetchMembershipsByProfileId, postMembershipByProfileId }
62
+
63
+const revealProfileInfo = async (membershipId, profileId, tagId) => {
64
+    const revealed = await db.post(
65
+        `/membership/${membershipId}/reveal?profile=${profileId}&tag=${tagId}`,
66
+    )
67
+    return revealed
68
+}
69
+
70
+export {
71
+    fetchMembershipsByProfileId,
72
+    postMembershipByProfileId,
73
+    revealProfileInfo,
74
+}

+ 0
- 2
frontend/src/services/login.service.js Zobrazit soubor

@@ -24,8 +24,6 @@ class Login {
24 24
         this.id = ref(null)
25 25
 
26 26
         this.groupings = []
27
-        this.responses = []
28
-
29 27
         this.queue = []
30 28
         this.responses = []
31 29
         this.tags = []

+ 22
- 2
frontend/src/views/ChatView.vue Zobrazit soubor

@@ -1,8 +1,16 @@
1 1
 <template lang="pug">
2 2
 main.view--chat
3
-    header.mb6(v-if='profile')
3
+    header.mb6(v-if='profile && grouping')
4 4
         h3 chatting with: {{ target.profile_id }}
5
-        p subscriptions: {{ profile.chatter.subscriptions }}
5
+        p {{ grouping.profile.user_name }}
6
+        p {{ grouping.profile.user_email }}
7
+        p {{ grouping.profile }}
8
+        //- p subscriptions: {{ profile.chatter.subscriptions }}
9
+        .w-flex.column
10
+            p reveal: {{ grouping.revealed }}
11
+            .w-flex.row
12
+                button(@click='reveal(7)') my name
13
+                button(@click='reveal(8)') my email
6 14
 
7 15
     article
8 16
         template(v-if='isLoading')
@@ -47,6 +55,15 @@ export default {
47 55
         messages: [],
48 56
         openDrawer: null,
49 57
     }),
58
+    computed: {
59
+        grouping() {
60
+            return this.profile.groupings.find(profileGrouping =>
61
+                profileGrouping.participants.includes(
62
+                    parseInt(this.$route.params.pid),
63
+                ),
64
+            )
65
+        },
66
+    },
50 67
     watch: {
51 68
         profile() {
52 69
             this.loadTargetProfile()
@@ -58,6 +75,9 @@ export default {
58 75
         currentProfile.chatter.setOnMessage(this._onMessage)
59 76
     },
60 77
     methods: {
78
+        reveal(tagId) {
79
+            this.grouping.reveal(currentProfile.profile_id, tagId)
80
+        },
61 81
         /**
62 82
          * Pubnub message callback fires when message event
63 83
          * is detected. We define is HERE because we need the

Načítá se…
Zrušit
Uložit