Sfoglia il codice sorgente

:bug: fixing membership bugs in the frontend | adding more mock groupings and relationships to test

tags/0.0.1^2
J 3 anni fa
parent
commit
d2eb9cfb74

+ 45
- 0
backend/db/data-generator/mock.js Vedi File

208
         { match_queue_id: 4, profile_id: 46, target_id: 62, is_deleted: false },
208
         { match_queue_id: 4, profile_id: 46, target_id: 62, is_deleted: false },
209
         { match_queue_id: 5, profile_id: 45, target_id: 46, is_deleted: false },
209
         { match_queue_id: 5, profile_id: 45, target_id: 46, is_deleted: false },
210
         { match_queue_id: 6, profile_id: 46, target_id: 45, is_deleted: false },
210
         { match_queue_id: 6, profile_id: 46, target_id: 45, is_deleted: false },
211
+        { match_queue_id: 7, profile_id: 46, target_id: 44, is_deleted: false },
212
+        { match_queue_id: 8, profile_id: 46, target_id: 43, is_deleted: false },
213
+        { match_queue_id: 9, profile_id: 46, target_id: 42, is_deleted: false },
214
+        {
215
+            match_queue_id: 10,
216
+            profile_id: 46,
217
+            target_id: 41,
218
+            is_deleted: false,
219
+        },
220
+        {
221
+            match_queue_id: 11,
222
+            profile_id: 46,
223
+            target_id: 40,
224
+            is_deleted: false,
225
+        },
226
+        {
227
+            match_queue_id: 12,
228
+            profile_id: 40,
229
+            target_id: 46,
230
+            is_deleted: false,
231
+        },
232
+        {
233
+            match_queue_id: 13,
234
+            profile_id: 41,
235
+            target_id: 46,
236
+            is_deleted: false,
237
+        },
238
+        {
239
+            match_queue_id: 14,
240
+            profile_id: 42,
241
+            target_id: 46,
242
+            is_deleted: false,
243
+        },
244
+        {
245
+            match_queue_id: 15,
246
+            profile_id: 43,
247
+            target_id: 46,
248
+            is_deleted: false,
249
+        },
250
+        {
251
+            match_queue_id: 16,
252
+            profile_id: 44,
253
+            target_id: 46,
254
+            is_deleted: false,
255
+        },
211
     ],
256
     ],
212
 }
257
 }

+ 19
- 19
backend/lib/routes/membership/join.js Vedi File

48
          */
48
          */
49
         handler: async function (request, h) {
49
         handler: async function (request, h) {
50
             try {
50
             try {
51
+                console.log('---')
51
                 const { membershipService } = request.server.services()
52
                 const { membershipService } = request.server.services()
52
 
53
 
53
                 /** Grab payload info */
54
                 /** Grab payload info */
73
                     groupingToWrite,
74
                     groupingToWrite,
74
                     role,
75
                     role,
75
                 )
76
                 )
76
-                // console.log(memberships)
77
                 const hasMatch = memberships.every(
77
                 const hasMatch = memberships.every(
78
                     membership => membership && membership.is_active == true,
78
                     membership => membership && membership.is_active == true,
79
                 )
79
                 )
80
-                request.server.methods.notify(
81
-                    `${profileId}.stonk`,
82
-                    {
83
-                        name: `${res.target_id} Match Fffound`,
84
-                        type: 'info',
85
-                    },
86
-                    h,
87
-                )
88
-                request.server.methods.notify(
89
-                    `${res.target_id}.stonk`,
90
-                    {
91
-                        name: `${profileId} Match Fffound`,
92
-                        type: 'info',
93
-                    },
94
-                    h,
95
-                )
96
-                console.log('hasMatch :>> ', hasMatch)
97
-                console.log('memberships :>> ', memberships)
98
 
80
 
81
+                if (hasMatch) {
82
+                    request.server.methods.notify(
83
+                        `${profileId}.stonk`,
84
+                        {
85
+                            name: `${res.target_id} Match Fffound`,
86
+                            type: 'info',
87
+                        },
88
+                        h,
89
+                    )
90
+                    request.server.methods.notify(
91
+                        `${res.target_id}.stonk`,
92
+                        {
93
+                            name: `${profileId} Match Fffound`,
94
+                            type: 'info',
95
+                        },
96
+                        h,
97
+                    )
98
+                }
99
                 return h
99
                 return h
100
                     .response({
100
                     .response({
101
                         ok: true,
101
                         ok: true,

+ 9
- 5
backend/lib/routes/profile/patch-queue.js Vedi File

16
 
16
 
17
 const responseSchemas = {
17
 const responseSchemas = {
18
     response: Joi.array().items(
18
     response: Joi.array().items(
19
-        Joi.alternatives().try(Joi.number().optional(), profileSchema.single),
19
+        Joi.alternatives().try(
20
+            Joi.number().optional(),
21
+            profileSchema.single.optional(),
22
+        ),
20
     ),
23
     ),
21
     error: errorSchema.single,
24
     error: errorSchema.single,
22
 }
25
 }
47
                 reinsert,
50
                 reinsert,
48
             )
51
             )
49
             const queueIds = updatedQueue.map(entry => entry.target_id)
52
             const queueIds = updatedQueue.map(entry => entry.target_id)
53
+
50
             const res = {
54
             const res = {
51
                 ok: true,
55
                 ok: true,
52
                 handler: pluginConfig.handlerType,
56
                 handler: pluginConfig.handlerType,
53
-                data: queueIds,
54
-            }
55
-            if (include_profile) {
56
-                res.data = await profileService.getProfilesFor(queueIds)
57
+                data:
58
+                    include_profile == true
59
+                        ? await profileService.getProfilesFor(queueIds)
60
+                        : queueIds,
57
             }
61
             }
58
 
62
 
59
             try {
63
             try {

+ 3
- 5
backend/lib/schemas/responses.js Vedi File

6
     response_key_id: Joi.number(),
6
     response_key_id: Joi.number(),
7
     response_id: Joi.number(),
7
     response_id: Joi.number(),
8
     profile_id: Joi.number(),
8
     profile_id: Joi.number(),
9
-    val: Joi.string(),
9
+    val: Joi.string().allow(null, ''),
10
 }).label('response_single')
10
 }).label('response_single')
11
 
11
 
12
 const singleResponseKey = Joi.object({
12
 const singleResponseKey = Joi.object({
18
 
18
 
19
 module.exports = {
19
 module.exports = {
20
     single: singleResponse,
20
     single: singleResponse,
21
-    list: Joi.array().items(singleResponse.optional()).label('response_list'),
21
+    list: Joi.array().items(singleResponse).label('response_list'),
22
     key: singleResponseKey,
22
     key: singleResponseKey,
23
-    keys: Joi.array()
24
-        .items(singleResponseKey.optional())
25
-        .label('question_list'),
23
+    keys: Joi.array().items(singleResponseKey).label('question_list'),
26
 }
24
 }

+ 8
- 34
backend/lib/services/membership.js Vedi File

10
      * @param {number} profileId
10
      * @param {number} profileId
11
      * @returns {Array} List of all grouping_ids for user
11
      * @returns {Array} List of all grouping_ids for user
12
      */
12
      */
13
-    async _getGroupingIdsForProfileId(profileId, type, active) {
13
+    async _getGroupingIdsForProfileId(profileId) {
14
         const { Membership } = this.server.models()
14
         const { Membership } = this.server.models()
15
 
15
 
16
         /** Grab every Membership associated with this id */
16
         /** Grab every Membership associated with this id */
17
-        let allMemberships = []
18
-
19
-        if (type && active == 'any') {
20
-            allMemberships = await Membership.query()
21
-                .where({ profile_id: profileId })
22
-                .where({ membership_type: type })
23
-        } else if (type) {
24
-            allMemberships = await Membership.query()
25
-                .where({ profile_id: profileId })
26
-                .where({ membership_type: type })
27
-                .where({ is_active: true })
28
-        } else if (active == 'any') {
29
-            allMemberships = await Membership.query().where({
30
-                profile_id: profileId,
31
-            })
32
-        } else {
33
-            allMemberships = await Membership.query()
34
-                .where({ profile_id: profileId })
35
-                .where({ is_active: true })
36
-        }
37
-
38
-        /** Copy a list of the just the Groupings */
17
+        const allMemberships = await Membership.query().where({
18
+            profile_id: profileId,
19
+        })
20
+        /** Copy a list of the just the Grouping ids */
39
         const groupingIdsToGrab = allMemberships.map(
21
         const groupingIdsToGrab = allMemberships.map(
40
             membership => membership.grouping_id,
22
             membership => membership.grouping_id,
41
         )
23
         )
81
      */
63
      */
82
     async findGroupingsByProfileId(profileId, type) {
64
     async findGroupingsByProfileId(profileId, type) {
83
         const { Grouping } = this.server.models()
65
         const { Grouping } = this.server.models()
84
-
85
         const dedupedGroupings = await this._getGroupingIdsForProfileId(
66
         const dedupedGroupings = await this._getGroupingIdsForProfileId(
86
             profileId,
67
             profileId,
87
             type,
68
             type,
88
-            'any',
89
         )
69
         )
90
-
91
         /** Grab just the Groupings this id has a Membership for */
70
         /** Grab just the Groupings this id has a Membership for */
92
         return await Grouping.query()
71
         return await Grouping.query()
93
             .whereIn('grouping_id', dedupedGroupings)
72
             .whereIn('grouping_id', dedupedGroupings)
95
     }
74
     }
96
 
75
 
97
     async _groupingIdsInCommon(profileId, targetId) {
76
     async _groupingIdsInCommon(profileId, targetId) {
98
-        const dedupedUserGroupingIds = await this._getGroupingIdsForProfileId(
99
-            profileId,
100
-        )
101
-        const dedupedTargetGroupingIds = await this._getGroupingIdsForProfileId(
102
-            targetId,
103
-        )
77
+        const uids = await this._getGroupingIdsForProfileId(profileId)
78
+        const tids = await this._getGroupingIdsForProfileId(targetId)
104
         const common = []
79
         const common = []
105
-        const uids = dedupedUserGroupingIds.toString().split(',').map(Number)
106
-        const tids = dedupedTargetGroupingIds.toString().split(',').map(Number)
107
         for (let i in uids) {
80
         for (let i in uids) {
108
             if (tids.indexOf(uids[i]) !== -1) common.push(uids[i])
81
             if (tids.indexOf(uids[i]) !== -1) common.push(uids[i])
109
         }
82
         }
110
         return common.sort((x, y) => x - y)
83
         return common.sort((x, y) => x - y)
111
     }
84
     }
85
+
112
     async _patchMembership(memberships, profileId, patch) {
86
     async _patchMembership(memberships, profileId, patch) {
113
         const { Membership } = this.server.models()
87
         const { Membership } = this.server.models()
114
 
88
 

+ 8
- 4
frontend/src/App.vue Vedi File

1
 <template lang="pug">
1
 <template lang="pug">
2
 w-app
2
 w-app
3
-    div.nav(v-if="getPid" style="display: flex; justify-content: space-between;")
3
+    div.nav(v-if="isLoggedIn" style="display: flex; justify-content: space-between;")
4
         header
4
         header
5
             h2 home - profile: {{ getPid }}
5
             h2 home - profile: {{ getPid }}
6
         w-drawer(v-model="openDrawer")
6
         w-drawer(v-model="openDrawer")
12
         w-button(@click="openDrawer = true" outline="")
12
         w-button(@click="openDrawer = true" outline="")
13
             | Active Chats
13
             | Active Chats
14
     RouterView(
14
     RouterView(
15
-        v-if="getPid"
15
+        v-if="isLoggedIn"
16
         :pid="getPid"
16
         :pid="getPid"
17
         @updatePid="setPid"
17
         @updatePid="setPid"
18
         @show-sidebar="showSidebar = !showSidebar"
18
         @show-sidebar="showSidebar = !showSidebar"
37
         openDrawer: false,
37
         openDrawer: false,
38
     }),
38
     }),
39
     computed: {
39
     computed: {
40
-        getPid: () =>
41
-            currentProfile.id.value ? currentProfile.id.value : null,
40
+        getPid: () => {
41
+            return currentProfile.id.value ? currentProfile.id.value : null
42
+        },
43
+        isLoggedIn: () => {
44
+            return currentProfile.isLoggedIn
45
+        },
42
     },
46
     },
43
     async created() {
47
     async created() {
44
         /** Get questions so we can compare against profile responses */
48
         /** Get questions so we can compare against profile responses */

+ 16
- 16
frontend/src/components/ProfileCardList.vue Vedi File

20
                     nav.swipe_icons
20
                     nav.swipe_icons
21
                         //- Accept
21
                         //- Accept
22
                         button(@click="chat(profile.pid)") chat
22
                         button(@click="chat(profile.pid)") chat
23
-                        button(@click="accept") Accept
23
+                        button(@click="accept(profile.pid)") Accept
24
                         button(@click="view(profile.pid)") view
24
                         button(@click="view(profile.pid)") view
25
                         //- Pass
25
                         //- Pass
26
-                        button(@click="pass") Pass
26
+                        button(@click="pass(profile.pid)") Pass
27
     
27
     
28
     .match-layout(
28
     .match-layout(
29
         v-else
29
         v-else
46
 import { useRouter } from 'vue-router'
46
 import { useRouter } from 'vue-router'
47
 import {
47
 import {
48
     updateQueueByProfileId,
48
     updateQueueByProfileId,
49
-    fetchMembershipsByProfileId,
50
     postMembershipByProfileId,
49
     postMembershipByProfileId,
51
     currentProfile,
50
     currentProfile,
52
 } from '../services'
51
 } from '../services'
89
 
88
 
90
 // AHP Button behavior
89
 // AHP Button behavior
91
 
90
 
92
-const accept = async () => {
91
+const accept = async targetId => {
92
+    if (targetId == props.pid) return
93
     // need to pass these arguments (profileId, targetId, status)
93
     // need to pass these arguments (profileId, targetId, status)
94
     // the url structure is
94
     // the url structure is
95
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
95
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
96
     // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
96
     // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
97
     const profileId = props.pid
97
     const profileId = props.pid
98
-    const targetId = props.profiles[0].pid
99
     updateQueueByProfileId(profileId, targetId, false)
98
     updateQueueByProfileId(profileId, targetId, false)
100
-    // TODO: next step is grouping/membership
101
-    const checkMembership = await fetchMembershipsByProfileId(profileId)
102
-    if (!checkMembership.length) {
103
-        postMembershipByProfileId({ profileId, targetId })
104
-    }
99
+
100
+    postMembershipByProfileId({ profileId, targetId })
101
+
105
     emit('reload')
102
     emit('reload')
106
 }
103
 }
104
+
107
 const view = pid => {
105
 const view = pid => {
108
     router.push({ path: `/matches/${pid}` })
106
     router.push({ path: `/matches/${pid}` })
109
 }
107
 }
110
-const chat = async pid => {
108
+
109
+const chat = async targetId => {
111
     // create a chatter reference from the current profile
110
     // create a chatter reference from the current profile
112
     const chatter = currentProfile.chatter
111
     const chatter = currentProfile.chatter
113
     // console.log('mock sender:', pid)
112
     // console.log('mock sender:', pid)
114
-    
113
+
115
     /**  publish a new message to the chatter with the channel and the message & title is optional
114
     /**  publish a new message to the chatter with the channel and the message & title is optional
116
      */
115
      */
117
     const res = await chatter.publish(chatter.subscriptions[1], {
116
     const res = await chatter.publish(chatter.subscriptions[1], {
118
         title: 'New Message',
117
         title: 'New Message',
119
-        description: 'This is the checking to see if we are subscribed to a channel!',
118
+        description:
119
+            'This is the checking to see if we are subscribed to a channel!',
120
     })
120
     })
121
     // PubNub response will be a timecode of when the message was published
121
     // PubNub response will be a timecode of when the message was published
122
     console.log('res:', res)
122
     console.log('res:', res)
123
-
124
     //router.push({ path: `/chat/${pid}` })
123
     //router.push({ path: `/chat/${pid}` })
125
 }
124
 }
126
-const pass = () => {
127
-    const targetId = props.profiles[0].pid
125
+
126
+const pass = targetId => {
127
+    if (targetId == props.pid) return
128
     updateQueueByProfileId(props.pid, targetId, true)
128
     updateQueueByProfileId(props.pid, targetId, true)
129
     emit('reload')
129
     emit('reload')
130
 }
130
 }

+ 1
- 1
frontend/src/components/SideBar.vue Vedi File

1
 <template lang="pug">
1
 <template lang="pug">
2
 aside.sidebar
2
 aside.sidebar
3
     .temp-control-box
3
     .temp-control-box
4
-        input(v-model="switchToPID")
4
+        input(v-model="switchToPID" @keyup.enter="$emit('updatePid', switchToPID)")
5
         button(@click="$emit('updatePid', switchToPID)") switch profile
5
         button(@click="$emit('updatePid', switchToPID)") switch profile
6
     
6
     
7
     Messages(:matches="matches" :pid="pid")
7
     Messages(:matches="matches" :pid="pid")

+ 2
- 2
frontend/src/services/grouping.service.js Vedi File

34
     targetId,
34
     targetId,
35
     groupingType = 'match',
35
     groupingType = 'match',
36
 }) => {
36
 }) => {
37
-    const utcDateInSeconds = Date.now()/1000
37
+    const utcDateInSeconds = Date.now() / 1000
38
     const membership = {
38
     const membership = {
39
         target_id: targetId,
39
         target_id: targetId,
40
         grouping_type: groupingType,
40
         grouping_type: groupingType,
41
         grouping_name: `${utcDateInSeconds}_${profileId}_${targetId}`,
41
         grouping_name: `${utcDateInSeconds}_${profileId}_${targetId}`,
42
     }
42
     }
43
-    console.warn(`${groupingType} created between ${profileId} and ${targetId}`)
44
     const createdMembershipRecord = await db.post(
43
     const createdMembershipRecord = await db.post(
45
         `/membership/${profileId}/join`,
44
         `/membership/${profileId}/join`,
46
         membership,
45
         membership,
47
     )
46
     )
47
+    console.warn(`${groupingType} created between ${profileId} and ${targetId}`)
48
     return createdMembershipRecord
48
     return createdMembershipRecord
49
 }
49
 }
50
 export { fetchMembershipsByProfileId, postMembershipByProfileId }
50
 export { fetchMembershipsByProfileId, postMembershipByProfileId }

Loading…
Annulla
Salva