Преглед на файлове

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

tags/0.0.3^2
j преди 3 години
родител
ревизия
87a928002e

+ 26
- 0
backend/db/data-generator/mock.js Целия файл

38
             tag_description: 'urgency',
38
             tag_description: 'urgency',
39
             is_active: true,
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
     tag_associations: [
54
     tag_associations: [
43
         {
55
         {
89
             tag_id: 5,
101
             tag_id: 5,
90
             is_deleted: false,
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
     response_keys: [
119
     response_keys: [
94
         {
120
         {

+ 2
- 0
backend/lib/plugins/membership.js Целия файл

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

+ 0
- 1
backend/lib/routes/membership/active.js Целия файл

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

+ 104
- 0
backend/lib/routes/membership/reveal.js Целия файл

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 Целия файл

374
     async revealProfileInfo(association) {
374
     async revealProfileInfo(association) {
375
         const { TagAssociation } = this.server.models()
375
         const { TagAssociation } = this.server.models()
376
         await TagAssociation.query().insert(association)
376
         await TagAssociation.query().insert(association)
377
+
377
         return await this.getTagsFor(association.profile_id)
378
         return await this.getTagsFor(association.profile_id)
378
     }
379
     }
379
 }
380
 }

+ 1
- 1
backend/lib/services/profile/profiler.js Целия файл

14
         this.user_email = profile.user.user_email
14
         this.user_email = profile.user.user_email
15
         this.responses = []
15
         this.responses = []
16
         this.user_type = type
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
         // TODO: generalize this for multiple images, and languages
19
         // TODO: generalize this for multiple images, and languages
20
         this.profile_description = ''
20
         this.profile_description = ''

+ 1
- 0
frontend/src/entities/card/card.js Целия файл

97
 
97
 
98
         this.images = []
98
         this.images = []
99
         this.tags = []
99
         this.tags = []
100
+        this.reveal = {}
100
 
101
 
101
         this.summary = new SummaryGroup()
102
         this.summary = new SummaryGroup()
102
 
103
 

+ 21
- 0
frontend/src/entities/grouping/grouping.js Целия файл

2
 
2
 
3
 import { _baseRecord } from '../index.js'
3
 import { _baseRecord } from '../index.js'
4
 import { groupingSchema } from './grouping.schema.js'
4
 import { groupingSchema } from './grouping.schema.js'
5
+// import { revealProfileInfo } from '../../services/profile.service.js'
5
 
6
 
6
 /** Class representing a grouping */
7
 /** Class representing a grouping */
7
 class Grouping extends _baseRecord {
8
 class Grouping extends _baseRecord {
22
 
23
 
23
         return this
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
      * validate this record
47
      * validate this record
27
      * @return {boolean} is it valid or not?
48
      * @return {boolean} is it valid or not?

+ 21
- 4
frontend/src/services/grouping.service.js Целия файл

15
         memberships = await db.get(`/membership/${profileId}`)
15
         memberships = await db.get(`/membership/${profileId}`)
16
         for (let membership of memberships) {
16
         for (let membership of memberships) {
17
             const grouping = new Grouping(membership)
17
             const grouping = new Grouping(membership)
18
-            grouping.tags = await db.get(
19
-                `/profile/${profileId}/tags/${grouping.grouping_id}`,
20
-            )
21
             if (grouping.isValid()) {
18
             if (grouping.isValid()) {
22
                 // Reformat incoming profile data into Profile entity
19
                 // Reformat incoming profile data into Profile entity
23
                 grouping.profile = new Profile(grouping.profile)
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
                 validGroupingInstances.push(grouping)
29
                 validGroupingInstances.push(grouping)
25
             }
30
             }
26
         }
31
         }
54
     )
59
     )
55
     return { membershipMatch, groupingName: membership.grouping_name }
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 Целия файл

24
         this.id = ref(null)
24
         this.id = ref(null)
25
 
25
 
26
         this.groupings = []
26
         this.groupings = []
27
-        this.responses = []
28
-
29
         this.queue = []
27
         this.queue = []
30
         this.responses = []
28
         this.responses = []
31
         this.tags = []
29
         this.tags = []

+ 22
- 2
frontend/src/views/ChatView.vue Целия файл

1
 <template lang="pug">
1
 <template lang="pug">
2
 main.view--chat
2
 main.view--chat
3
-    header.mb6(v-if='profile')
3
+    header.mb6(v-if='profile && grouping')
4
         h3 chatting with: {{ target.profile_id }}
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
     article
15
     article
8
         template(v-if='isLoading')
16
         template(v-if='isLoading')
47
         messages: [],
55
         messages: [],
48
         openDrawer: null,
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
     watch: {
67
     watch: {
51
         profile() {
68
         profile() {
52
             this.loadTargetProfile()
69
             this.loadTargetProfile()
58
         currentProfile.chatter.setOnMessage(this._onMessage)
75
         currentProfile.chatter.setOnMessage(this._onMessage)
59
     },
76
     },
60
     methods: {
77
     methods: {
78
+        reveal(tagId) {
79
+            this.grouping.reveal(currentProfile.profile_id, tagId)
80
+        },
61
         /**
81
         /**
62
          * Pubnub message callback fires when message event
82
          * Pubnub message callback fires when message event
63
          * is detected. We define is HERE because we need the
83
          * is detected. We define is HERE because we need the

Loading…
Отказ
Запис