Parcourir la source

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

tags/0.0.1^2
J il y a 3 ans
Parent
révision
d2eb9cfb74

+ 45
- 0
backend/db/data-generator/mock.js Voir le fichier

@@ -208,5 +208,50 @@ module.exports = {
208 208
         { match_queue_id: 4, profile_id: 46, target_id: 62, is_deleted: false },
209 209
         { match_queue_id: 5, profile_id: 45, target_id: 46, is_deleted: false },
210 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 Voir le fichier

@@ -48,6 +48,7 @@ module.exports = {
48 48
          */
49 49
         handler: async function (request, h) {
50 50
             try {
51
+                console.log('---')
51 52
                 const { membershipService } = request.server.services()
52 53
 
53 54
                 /** Grab payload info */
@@ -73,29 +74,28 @@ module.exports = {
73 74
                     groupingToWrite,
74 75
                     role,
75 76
                 )
76
-                // console.log(memberships)
77 77
                 const hasMatch = memberships.every(
78 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 99
                 return h
100 100
                     .response({
101 101
                         ok: true,

+ 9
- 5
backend/lib/routes/profile/patch-queue.js Voir le fichier

@@ -16,7 +16,10 @@ const pluginConfig = {
16 16
 
17 17
 const responseSchemas = {
18 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 24
     error: errorSchema.single,
22 25
 }
@@ -47,13 +50,14 @@ module.exports = {
47 50
                 reinsert,
48 51
             )
49 52
             const queueIds = updatedQueue.map(entry => entry.target_id)
53
+
50 54
             const res = {
51 55
                 ok: true,
52 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 63
             try {

+ 3
- 5
backend/lib/schemas/responses.js Voir le fichier

@@ -6,7 +6,7 @@ const singleResponse = Joi.object({
6 6
     response_key_id: Joi.number(),
7 7
     response_id: Joi.number(),
8 8
     profile_id: Joi.number(),
9
-    val: Joi.string(),
9
+    val: Joi.string().allow(null, ''),
10 10
 }).label('response_single')
11 11
 
12 12
 const singleResponseKey = Joi.object({
@@ -18,9 +18,7 @@ const singleResponseKey = Joi.object({
18 18
 
19 19
 module.exports = {
20 20
     single: singleResponse,
21
-    list: Joi.array().items(singleResponse.optional()).label('response_list'),
21
+    list: Joi.array().items(singleResponse).label('response_list'),
22 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 Voir le fichier

@@ -10,32 +10,14 @@ module.exports = class MembershipService extends Schmervice.Service {
10 10
      * @param {number} profileId
11 11
      * @returns {Array} List of all grouping_ids for user
12 12
      */
13
-    async _getGroupingIdsForProfileId(profileId, type, active) {
13
+    async _getGroupingIdsForProfileId(profileId) {
14 14
         const { Membership } = this.server.models()
15 15
 
16 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 21
         const groupingIdsToGrab = allMemberships.map(
40 22
             membership => membership.grouping_id,
41 23
         )
@@ -81,13 +63,10 @@ module.exports = class MembershipService extends Schmervice.Service {
81 63
      */
82 64
     async findGroupingsByProfileId(profileId, type) {
83 65
         const { Grouping } = this.server.models()
84
-
85 66
         const dedupedGroupings = await this._getGroupingIdsForProfileId(
86 67
             profileId,
87 68
             type,
88
-            'any',
89 69
         )
90
-
91 70
         /** Grab just the Groupings this id has a Membership for */
92 71
         return await Grouping.query()
93 72
             .whereIn('grouping_id', dedupedGroupings)
@@ -95,20 +74,15 @@ module.exports = class MembershipService extends Schmervice.Service {
95 74
     }
96 75
 
97 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 79
         const common = []
105
-        const uids = dedupedUserGroupingIds.toString().split(',').map(Number)
106
-        const tids = dedupedTargetGroupingIds.toString().split(',').map(Number)
107 80
         for (let i in uids) {
108 81
             if (tids.indexOf(uids[i]) !== -1) common.push(uids[i])
109 82
         }
110 83
         return common.sort((x, y) => x - y)
111 84
     }
85
+
112 86
     async _patchMembership(memberships, profileId, patch) {
113 87
         const { Membership } = this.server.models()
114 88
 

+ 8
- 4
frontend/src/App.vue Voir le fichier

@@ -1,6 +1,6 @@
1 1
 <template lang="pug">
2 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 4
         header
5 5
             h2 home - profile: {{ getPid }}
6 6
         w-drawer(v-model="openDrawer")
@@ -12,7 +12,7 @@ w-app
12 12
         w-button(@click="openDrawer = true" outline="")
13 13
             | Active Chats
14 14
     RouterView(
15
-        v-if="getPid"
15
+        v-if="isLoggedIn"
16 16
         :pid="getPid"
17 17
         @updatePid="setPid"
18 18
         @show-sidebar="showSidebar = !showSidebar"
@@ -37,8 +37,12 @@ export default {
37 37
         openDrawer: false,
38 38
     }),
39 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 47
     async created() {
44 48
         /** Get questions so we can compare against profile responses */

+ 16
- 16
frontend/src/components/ProfileCardList.vue Voir le fichier

@@ -20,10 +20,10 @@ section.profile-card-list(:style="{'display': 'flex', 'overflow':'auto',}")
20 20
                     nav.swipe_icons
21 21
                         //- Accept
22 22
                         button(@click="chat(profile.pid)") chat
23
-                        button(@click="accept") Accept
23
+                        button(@click="accept(profile.pid)") Accept
24 24
                         button(@click="view(profile.pid)") view
25 25
                         //- Pass
26
-                        button(@click="pass") Pass
26
+                        button(@click="pass(profile.pid)") Pass
27 27
     
28 28
     .match-layout(
29 29
         v-else
@@ -46,7 +46,6 @@ section.profile-card-list(:style="{'display': 'flex', 'overflow':'auto',}")
46 46
 import { useRouter } from 'vue-router'
47 47
 import {
48 48
     updateQueueByProfileId,
49
-    fetchMembershipsByProfileId,
50 49
     postMembershipByProfileId,
51 50
     currentProfile,
52 51
 } from '../services'
@@ -89,42 +88,43 @@ const randomize = max => {
89 88
 
90 89
 // AHP Button behavior
91 90
 
92
-const accept = async () => {
91
+const accept = async targetId => {
92
+    if (targetId == props.pid) return
93 93
     // need to pass these arguments (profileId, targetId, status)
94 94
     // the url structure is
95 95
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
96 96
     // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
97 97
     const profileId = props.pid
98
-    const targetId = props.profiles[0].pid
99 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 102
     emit('reload')
106 103
 }
104
+
107 105
 const view = pid => {
108 106
     router.push({ path: `/matches/${pid}` })
109 107
 }
110
-const chat = async pid => {
108
+
109
+const chat = async targetId => {
111 110
     // create a chatter reference from the current profile
112 111
     const chatter = currentProfile.chatter
113 112
     // console.log('mock sender:', pid)
114
-    
113
+
115 114
     /**  publish a new message to the chatter with the channel and the message & title is optional
116 115
      */
117 116
     const res = await chatter.publish(chatter.subscriptions[1], {
118 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 121
     // PubNub response will be a timecode of when the message was published
122 122
     console.log('res:', res)
123
-
124 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 128
     updateQueueByProfileId(props.pid, targetId, true)
129 129
     emit('reload')
130 130
 }

+ 1
- 1
frontend/src/components/SideBar.vue Voir le fichier

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

+ 2
- 2
frontend/src/services/grouping.service.js Voir le fichier

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

Chargement…
Annuler
Enregistrer