Explorar el Código

:sparkles: adding matcher to watch frontend for match notifications

tags/0.0.1^2
J hace 3 años
padre
commit
a1b56ab824

+ 0
- 11
backend/lib/routes/membership/active.js Ver fichero

81
                 return g
81
                 return g
82
             })
82
             })
83
 
83
 
84
-            request.server.methods.notify(
85
-                `${profileId}.stonk`,
86
-                {
87
-                    name: 'MSHRM',
88
-                    price: (500 + Math.floor(Math.random() * 100)).toString(),
89
-                    order: null,
90
-                    type: 'info',
91
-                },
92
-                h,
93
-            )
94
-
95
             try {
84
             try {
96
                 return {
85
                 return {
97
                     ok: true,
86
                     ok: true,

+ 15
- 3
backend/lib/routes/membership/join.js Ver fichero

74
                     role,
74
                     role,
75
                 )
75
                 )
76
                 // console.log(memberships)
76
                 // console.log(memberships)
77
+                const hasMatch = memberships.every(
78
+                    membership => membership.is_active == true,
79
+                )
80
+                if (hasMatch) {
81
+                    request.server.methods.notify(
82
+                        `${profileId}.match`,
83
+                        {
84
+                            name: 'Match Fffound',
85
+                            target: res.target_id,
86
+                            type: 'info',
87
+                        },
88
+                        h,
89
+                    )
90
+                }
77
 
91
 
78
                 return h
92
                 return h
79
                     .response({
93
                     .response({
81
                         handler: pluginConfig.handlerType,
95
                         handler: pluginConfig.handlerType,
82
                         data: {
96
                         data: {
83
                             memberships,
97
                             memberships,
84
-                            hasMatch: memberships.every(
85
-                                membership => membership.is_active == true,
86
-                            ),
98
+                            hasMatch,
87
                         },
99
                         },
88
                     })
100
                     })
89
                     .code(200)
101
                     .code(200)

+ 8
- 1
frontend/src/services/login.service.js Ver fichero

1
 import { ref } from 'vue'
1
 import { ref } from 'vue'
2
-import { fetchResponsesByProfileId, Chatter, StonkAlert } from '../services'
2
+import {
3
+    fetchResponsesByProfileId,
4
+    Chatter,
5
+    StonkAlert,
6
+    MatchAlert,
7
+} from '../services'
3
 import { surveyFactory } from '../utils'
8
 import { surveyFactory } from '../utils'
4
 
9
 
5
 
10
 
18
         this.tags = []
23
         this.tags = []
19
 
24
 
20
         this.toaster = null
25
         this.toaster = null
26
+        this.matcher = null
21
         this.chatter = null
27
         this.chatter = null
22
     }
28
     }
23
     get isLoading() {
29
     get isLoading() {
100
      */
106
      */
101
     setupToaster(waveCb) {
107
     setupToaster(waveCb) {
102
         this.toaster = new StonkAlert(this.id.value, waveCb)
108
         this.toaster = new StonkAlert(this.id.value, waveCb)
109
+        this.matcher = new MatchAlert(this.id.value, waveCb)
103
     }
110
     }
104
     setupChatter() {
111
     setupChatter() {
105
         this.chatter = new Chatter()
112
         this.chatter = new Chatter()

+ 16
- 1
frontend/src/services/notification.service.js Ver fichero

37
         return `${parsed.name}: ${parsed.profile_id} ${parsed.order} at ${parsed.price}`
37
         return `${parsed.name}: ${parsed.profile_id} ${parsed.order} at ${parsed.price}`
38
     }
38
     }
39
 }
39
 }
40
+class MatchAlert extends Toaster {
41
+    constructor(profileId, waveCb) {
42
+        super(profileId)
43
+        this.event = 'match'
44
+        this.matches = {}
45
+        this.listenFor(`${profileId}.${this.event}`, message => {
46
+            const parsed = JSON.parse(message.data)
47
+            this.matches[parsed.target] = parsed
48
+            waveCb(this._formatToast(parsed), parsed.type)
49
+        })
50
+    }
51
+    _formatToast(parsed) {
52
+        return `${parsed.name}: ${parsed.target}`
53
+    }
54
+}
40
 
55
 
41
-export { Toaster, StonkAlert }
56
+export { Toaster, StonkAlert, MatchAlert }

Loading…
Cancelar
Guardar