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

:recycle: Refactored notification to grab reveal description accurately

tags/0.0.3^2
tomit4 преди 3 години
родител
ревизия
34c691c84a
променени са 2 файла, в които са добавени 26 реда и са изтрити 22 реда
  1. 20
    10
      backend/lib/routes/membership/reveal.js
  2. 6
    12
      frontend/src/services/notification.service.js

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

51
                     membership => membership.profile_id,
51
                     membership => membership.profile_id,
52
                 )
52
                 )
53
 
53
 
54
-                // Grab User Info from Users Table and prepare revealed info for
55
-                // notification based off of tag_id
54
+                // Grab User Info from Users Table
56
                 const completeProfile = await profileService.getProfilesFor([profile_id], 'participant')
55
                 const completeProfile = await profileService.getProfilesFor([profile_id], 'participant')
57
-                let revealInfo
58
-                let tag_description
59
-                if (tag_id == 7) {
60
-                    revealInfo = completeProfile[0].user_name
61
-                    tag_description = 'name'
62
-                } else if (tag_id == 8) {
63
-                    revealInfo = completeProfile[0].user_email
64
-                    tag_description = 'email'
56
+
57
+                // Grab the TagAssociation that matches the revealed profile
58
+                // TODO: Check if there are multiple matching tags(?)(there shouldn't be)
59
+                const returnedTag = () => {
60
+                    let matchingTag
61
+                    tags.forEach(async (tagAssoc) => {
62
+                        if (tagAssoc.grouping_id === grouping_id &&
63
+                            tagAssoc.profile_id === profile_id &&
64
+                            tagAssoc.tag_id === tag_id) {
65
+                            matchingTag = tagAssoc
66
+                        }
67
+                    })
68
+                    if (matchingTag)
69
+                        return matchingTag
70
+                    return console.error('ERROR: No matching tagAssociation')
65
                 }
71
                 }
66
 
72
 
73
+                const tag_description = returnedTag().tag.tag_description
74
+                // TODO: Refactor completeProfile[0]... code smell
75
+                const revealInfo = completeProfile[0][tag_description]
76
+
67
                 idsInGroup.forEach(profile_id => {
77
                 idsInGroup.forEach(profile_id => {
68
                     request.server.methods.notify(
78
                     request.server.methods.notify(
69
                         `${profile_id}.stonk`,
79
                         `${profile_id}.stonk`,

+ 6
- 12
frontend/src/services/notification.service.js Целия файл

49
         )
49
         )
50
         if (foundGrouping) {
50
         if (foundGrouping) {
51
             const tagFromNotification = {
51
             const tagFromNotification = {
52
-                grouping_id: parsed.grouping_id,
53
-                is_deleted: 0,
54
-                profile_id: currentProfile._profile.profile_id,
55
-                target_id: foundGrouping.profile.profile_id,
56
-                tag: {
57
-                    is_active: 1,
58
-                    tag_category: "reveal",
59
-                    tag_description: parsed.description,
60
-                    tag_id: parsed.tag
61
-                }
52
+                is_active: 1,
53
+                tag_category: "reveal",
54
+                tag_description: parsed.description,
55
+                tag_id: parsed.tag
62
             }
56
             }
63
-            const target_desc = `target_${parsed.description}`
64
-            tagFromNotification.tag[target_desc] = parsed.revealed_info
57
+            const target_desc = parsed.description
58
+            tagFromNotification[target_desc] = parsed.revealed_info
65
             foundGrouping.profile.tags.push(tagFromNotification)
59
             foundGrouping.profile.tags.push(tagFromNotification)
66
         }
60
         }
67
     }
61
     }

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