ソースを参照

:bug: Addressed bugs involving validation and groupings

juan-filtering-match-pool
tomit4 2年前
コミット
73d9675bc8

+ 27
- 20
backend/lib/routes/membership/active.js ファイルの表示

@@ -71,19 +71,24 @@ module.exports = {
71 71
                 profileId,
72 72
                 membershipType,
73 73
             )
74
+            if (!groupings.length) {
75
+                return {
76
+                    ok: true,
77
+                    handler: pluginConfig.handlerType,
78
+                    data: [],
79
+                }
80
+            }
74 81
             const groupingIds = groupings.map(grouping => grouping.grouping_id)
75
-            const memberships = await membershipService.findMemberships(
76
-                groupingIds,
77
-            )
82
+            const memberships =
83
+                await membershipService.findMemberships(groupingIds)
78 84
             const profileIds = memberships
79 85
                 .filter(membership => membership.profile_id != profileId)
80 86
                 .map(membership => membership.profile_id)
81 87
 
82 88
             /** Assemble complete profiles to reference and pass */
83
-            const completedProfiles = await profileService.getProfilesFor(
84
-                profileIds,
85
-                'participant',
86
-            )
89
+            const completedProfiles = !profileIds.length
90
+                ? []
91
+                : await profileService.getProfilesFor(profileIds, 'participant')
87 92
 
88 93
             /**
89 94
              * Heavily process the result by storing just a profile_id
@@ -91,19 +96,21 @@ module.exports = {
91 96
              * !: This still assumes only ONE other profile
92 97
              * TODO: should be refactored to many other profiles
93 98
              */
94
-            const reformattedGroupings = groupings.map(grouping => {
95
-                const otherPid = grouping.profiles.find(
96
-                    p => p.profile_id != profileId,
97
-                ).profile_id
98
-                grouping.profile = completedProfiles.find(
99
-                    p => otherPid == p.profile_id,
100
-                )
101
-                grouping.is_paired = _activeGroupingIds(memberships).includes(
102
-                    grouping.grouping_id,
103
-                )
104
-                delete grouping.profiles
105
-                return grouping
106
-            })
99
+            const reformattedGroupings = groupings.length
100
+                ? groupings.map(grouping => {
101
+                      const otherPid = grouping.profiles.find(
102
+                          p => p.profile_id != profileId,
103
+                      ).profile_id
104
+                      grouping.profile = completedProfiles.find(
105
+                          p => otherPid == p.profile_id,
106
+                      )
107
+                      grouping.is_paired = _activeGroupingIds(
108
+                          memberships,
109
+                      ).includes(grouping.grouping_id)
110
+                      delete grouping.profiles
111
+                      return grouping
112
+                  })
113
+                : []
107 114
 
108 115
             /** Grabs revealTags */
109 116
             const revealTags = await profileService.getTagsFor(

+ 1
- 0
backend/lib/schemas/profiles.js ファイルの表示

@@ -15,6 +15,7 @@ const singleProfile = Joi.object({
15 15
     tags: tagSchema.list,
16 16
     media: Joi.any(),
17 17
     blurb: Joi.any(),
18
+    image: Joi.any(),
18 19
     user_type: Joi.any(),
19 20
     user: userSchema.single,
20 21
     profile_description: Joi.string().allow(null, ''),

+ 20
- 15
backend/lib/services/profile/index.js ファイルの表示

@@ -364,21 +364,26 @@ module.exports = class ProfileService extends Schmervice.Service {
364 364
     async getTagsFor(profileId, groupingId, category) {
365 365
         const { TagAssociation } = this.server.models()
366 366
         await this._setTagLookup()
367
-        let associations = groupingId
368
-            ? await TagAssociation.query()
369
-                  .where('grouping_id', groupingId)
370
-                  .andWhere('profile_id', profileId)
371
-            : await TagAssociation.query().andWhere('profile_id', profileId)
372
-        return associations
373
-            .map(assoc => ({
374
-                ...assoc,
375
-                tag: this.tagLookup[assoc.tag_id],
376
-            }))
377
-            .filter(tagWithAssoc => {
378
-                return category
379
-                    ? tagWithAssoc.tag.tag_category == category
380
-                    : true
381
-            })
367
+        let associations = []
368
+        if (!profileId.length || !groupingId.length) {
369
+            return associations
370
+        } else {
371
+            associations = groupingId
372
+                ? await TagAssociation.query()
373
+                      .where('grouping_id', groupingId)
374
+                      .andWhere('profile_id', profileId)
375
+                : await TagAssociation.query().andWhere('profile_id', profileId)
376
+            return associations
377
+                .map(assoc => ({
378
+                    ...assoc,
379
+                    tag: this.tagLookup[assoc.tag_id],
380
+                }))
381
+                .filter(tagWithAssoc => {
382
+                    return category
383
+                        ? tagWithAssoc.tag.tag_category == category
384
+                        : true
385
+                })
386
+        }
382 387
     }
383 388
 
384 389
     /**

+ 4
- 4
frontend/src/components/ProfileCard.vue ファイルの表示

@@ -101,7 +101,7 @@ const onTab = tabIndex => {
101 101
  * for both profileId and targetId
102 102
  */
103 103
 const onPair = async () => {
104
-    currentProfile._loading = true
104
+    currentProfile._loading.value = true
105 105
     const profileId = currentProfile.id.value
106 106
     const targetId = props.card.pid
107 107
     await postMembershipByProfileId({
@@ -110,7 +110,7 @@ const onPair = async () => {
110 110
     })
111 111
     await currentProfile.updateQueue(profileId, targetId, false)
112 112
     await currentProfile.getGroupings()
113
-    currentProfile._loading = false
113
+    currentProfile._loading.value = false
114 114
 
115 115
     let goToRoute = { name: 'HomeView' }
116 116
     router.push(goToRoute)
@@ -121,13 +121,13 @@ const onPair = async () => {
121 121
  * and forward back home
122 122
  */
123 123
 const onPass = async () => {
124
-    currentProfile._loading = true
124
+    currentProfile._loading.value = true
125 125
     await currentProfile.updateQueue(
126 126
         currentProfile.id.value,
127 127
         props.card.pid,
128 128
         true,
129 129
     )
130
-    currentProfile._loading = false
130
+    currentProfile._loading.value = false
131 131
 
132 132
     let goToRoute = { name: 'HomeView' }
133 133
     router.push(goToRoute)

読み込み中…
キャンセル
保存