Przeglądaj źródła

:recycle: Refactor of profiler logic

tags/0.0.3^2
tomit4 2 lat temu
rodzic
commit
d717f141e7

+ 1
- 1
backend/lib/schemas/profiles.js Wyświetl plik

@@ -13,7 +13,7 @@ const singleProfile = Joi.object({
13 13
     responses: surveyResponseSchema.list,
14 14
     reveal: Joi.array().items(),
15 15
     tags: tagSchema.list,
16
-    image: Joi.any(),
16
+    media: Joi.any(),
17 17
     blurb: Joi.any(),
18 18
     user_type: Joi.any(),
19 19
     user: userSchema.single,

+ 11
- 7
backend/lib/services/profile/profiler.js Wyświetl plik

@@ -25,22 +25,26 @@ class CompleteProfile {
25 25
         this.profile_id = profile.profile_id // int profile_id
26 26
         this.responses = profile.responses
27 27
         this.user_type = type
28
-
28
+        this.blurb = ''
29
+        this.profile_media = []
30
+        this.profile_languages = []
29 31
         this.profile_prefs = this.getPrefsFromResponses(this.responses)
30 32
 
31 33
         otherProfileInfo.forEach(prefName => {
32 34
             if (prefName == 'blurb') {
33
-                this.profile_description = this.responses.find(
35
+                const blurbRes = this.responses.find(
34 36
                     r => r.response_key_id === config.blurbKey,
35
-                ).val
37
+                )
38
+                this.profile_description = blurbRes ? blurbRes.val : ''
36 39
             } else if (['media', 'lang'].includes(prefName)) {
37 40
                 const key =
38 41
                     prefName == 'media'
39 42
                         ? `profile_${prefName}`
40 43
                         : [`profile_${prefName}uages`]
41
-                this[key] = this.responses
42
-                    .filter(r => r.response_key_id === config[`${prefName}Key`])
43
-                    .map(r => r.val)
44
+                const resForKey = this.responses.filter(
45
+                    r => r.response_key_id === config[`${prefName}Key`],
46
+                )
47
+                this[key] = resForKey.length ? resForKey.map(r => r.val) : []
44 48
             }
45 49
         })
46 50
         // TODO: These should be getters
@@ -54,7 +58,7 @@ class CompleteProfile {
54 58
         return unscoredProfilePreferences.reduce((byPref, prefName) => {
55 59
             byPref[prefName] = this.responses.find(
56 60
                 r => config[`${prefName}Key`] == r.response_key_id,
57
-            ).val
61
+            )?.val
58 62
             return byPref
59 63
         }, {})
60 64
     }

Ładowanie…
Anuluj
Zapisz