Просмотр исходного кода

:sparkles: sse push updates!

tags/0.0.1
J 4 лет назад
Родитель
Сommit
1e6b2e2dfd

+ 5
- 0
backend/lib/index.js Просмотреть файл

@@ -2,6 +2,7 @@ const UserPlugin = require('./plugins/user')
2 2
 const MembershipPlugin = require('./plugins/membership')
3 3
 const SurveyPlugin = require('./plugins/survey')
4 4
 const ProfilePlugin = require('./plugins/profile')
5
+const NotificationPlugin = require('./plugins/notification')
5 6
 
6 7
 /**
7 8
  * A Hapi server instance
@@ -40,5 +41,9 @@ exports.plugin = {
40 41
         await server.register(ProfilePlugin, {
41 42
             routes: { prefix: '/profile' },
42 43
         })
44
+        
45
+        await server.register(NotificationPlugin, {
46
+            routes: { prefix: '/notification' },
47
+        })
43 48
     },
44 49
 }

+ 75
- 0
backend/lib/plugins/notification.js Просмотреть файл

@@ -0,0 +1,75 @@
1
+const Stream = require('stream')
2
+const PassThrough = Stream.PassThrough
3
+const Transform = Stream.Transform
4
+const NotificationRoute = require('../routes/notification')
5
+
6
+const stringifyEvent = function (event) {
7
+    let str = ''
8
+    const endl = '\r\n'
9
+    for (const i in event) {
10
+        let val = event[i]
11
+        if (val instanceof Buffer) { val = val.toString() }
12
+        if (typeof val === 'object') { val = JSON.stringify(val) }
13
+        str += i + ': ' + val + endl
14
+    }
15
+    str += endl
16
+    return str
17
+}
18
+
19
+class Transformer extends Transform {
20
+    constructor(options, objectMode) {
21
+        super({ objectMode })
22
+        options = options || {}
23
+        this.counter = 1
24
+        this.event = options.event || null
25
+        this.generateId = options.generateId ? options.generateId : () => {
26
+            return this.counter++
27
+        }
28
+    }
29
+    _transform (chunk, encoding, callback) {
30
+        const event = {
31
+            id: this.generateId(chunk),
32
+            data: chunk
33
+        }
34
+        if (this.event) { event.event = this.event }
35
+        this.push(stringifyEvent(event))
36
+        callback()
37
+    }
38
+    _flush(callback) {
39
+        this.push(stringifyEvent({ event: 'end', data: '' }))
40
+        callback()
41
+    }
42
+} 
43
+
44
+const writeEvent = function (event, stream) {
45
+    if (event) {
46
+        stream.write(stringifyEvent(event))
47
+    } else {
48
+        // closing time
49
+        stream.write(stringifyEvent({ event: 'end', data: '' }))
50
+        stream.end()
51
+    }
52
+}
53
+
54
+const onEvent = (event, h, streamOptions) => {
55
+    // We only support ObjectMode streams
56
+    if (!event._readableState.objectMode) return
57
+
58
+    const through = new Transformer(streamOptions, true)
59
+    const active = new PassThrough()
60
+    through.pipe(active)
61
+    event.pipe(through)
62
+    console.log(event)
63
+    return h.response(active)
64
+        .header('content-type', 'text/event-stream')
65
+        .header('content-encoding', 'identity')
66
+}
67
+
68
+module.exports = {
69
+    name: 'notification-plugin',
70
+    version: '1.0.0',
71
+    register: async (server, options) => {
72
+        await server.route(NotificationRoute)
73
+        server.decorate('toolkit', 'event', onEvent)
74
+    }
75
+}

+ 1
- 1
backend/lib/routes/membership/join.js Просмотреть файл

@@ -70,7 +70,7 @@ module.exports = {
70 70
                     groupingToWrite,
71 71
                     role,
72 72
                 )
73
-
73
+                // console.log(memberships)
74 74
                 return h
75 75
                     .response({
76 76
                         ok: true,

+ 53
- 0
backend/lib/routes/notification/index.js Просмотреть файл

@@ -0,0 +1,53 @@
1
+const Joi = require('joi')
2
+const apiSchema = require('../../schemas/api')
3
+const errorSchema = require('../../schemas/errors')
4
+const Stream = require('stream')
5
+const PassThrough = require('stream').PassThrough
6
+
7
+const pluginConfig = {
8
+    handlerType: 'notifictaion',
9
+    docs: {
10
+        description: 'subscribe',
11
+        notes: 'Subscribe to notifications based on profile_id',
12
+    },
13
+}
14
+
15
+const validators = {
16
+    params: Joi.object({
17
+        profile_id: Joi.number(),
18
+    })
19
+}
20
+
21
+module.exports = {
22
+    method: 'GET',
23
+    path: '/{profile_id}/subscribe',
24
+    options: {
25
+        ...pluginConfig.docs,
26
+        tags: ['api'],
27
+        auth: false,
28
+        cors: true,
29
+        handler: async (request, h) => {
30
+            const input = new PassThrough({ objectMode: true })
31
+            const eventType = 'stonk'
32
+
33
+            const msg = { name: 'BDGRS', price: (500 + Math.floor(Math.random() * 100)).toString(), order: null }
34
+
35
+            // Write to the input stream
36
+            setInterval(() => {
37
+                msg.order = Math.floor(Math.random() * 2) === 1 ? 'BUY' : 'SELL'
38
+                input.write(msg)
39
+            }, 5000)
40
+
41
+            // h.event() Added at plugin registration
42
+            // h is the toolkit
43
+            return h.event(input, h, { event: eventType })
44
+        },
45
+
46
+        /** Validate based on validators object */
47
+         validate: {
48
+            ...validators,
49
+            failAction: 'log'
50
+        },
51
+
52
+    },
53
+}

+ 8
- 0
backend/lib/routes/profile/queue.js Просмотреть файл

@@ -59,6 +59,14 @@ module.exports = {
59 59
                 data: queueIds
60 60
             }
61 61
 
62
+            // HELP: I think there's an issue here
63
+            // queueIds spits out the queue profiles in the correct order
64
+            // ~However~ when it goes through getProfilesFor
65
+            // it comes back in literal database order regardless of is_deleted status
66
+            // console.log(
67
+            //     'include_profile results',
68
+            //     await profileService.getProfilesFor(queueIds),
69
+            // )
62 70
             if(include_profile) {
63 71
                 res.data = await profileService.getProfilesFor(queueIds)
64 72
             }

+ 27
- 27
backend/package-lock.json Просмотреть файл

@@ -1052,9 +1052,9 @@
1052 1052
       "dev": true
1053 1053
     },
1054 1054
     "ansi-regex": {
1055
-      "version": "5.0.0",
1056
-      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
1057
-      "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
1055
+      "version": "5.0.1",
1056
+      "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
1057
+      "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
1058 1058
       "dev": true
1059 1059
     },
1060 1060
     "ansi-styles": {
@@ -1240,25 +1240,25 @@
1240 1240
           "dev": true
1241 1241
         },
1242 1242
         "boxen": {
1243
-          "version": "5.0.1",
1244
-          "resolved": "https://registry.npmjs.org/boxen/-/boxen-5.0.1.tgz",
1245
-          "integrity": "sha512-49VBlw+PrWEF51aCmy7QIteYPIFZxSpvqBdP/2itCPPlJ49kj9zg/XPRFrdkne2W+CfwXUls8exMvu1RysZpKA==",
1243
+          "version": "5.1.2",
1244
+          "resolved": "https://registry.npmjs.org/boxen/-/boxen-5.1.2.tgz",
1245
+          "integrity": "sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ==",
1246 1246
           "dev": true,
1247 1247
           "requires": {
1248 1248
             "ansi-align": "^3.0.0",
1249 1249
             "camelcase": "^6.2.0",
1250 1250
             "chalk": "^4.1.0",
1251 1251
             "cli-boxes": "^2.2.1",
1252
-            "string-width": "^4.2.0",
1252
+            "string-width": "^4.2.2",
1253 1253
             "type-fest": "^0.20.2",
1254 1254
             "widest-line": "^3.1.0",
1255 1255
             "wrap-ansi": "^7.0.0"
1256 1256
           }
1257 1257
         },
1258 1258
         "camelcase": {
1259
-          "version": "6.2.0",
1260
-          "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz",
1261
-          "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==",
1259
+          "version": "6.3.0",
1260
+          "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz",
1261
+          "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==",
1262 1262
           "dev": true
1263 1263
         },
1264 1264
         "chalk": {
@@ -3063,17 +3063,17 @@
3063 3063
       }
3064 3064
     },
3065 3065
     "hapi-swagger": {
3066
-      "version": "14.1.3",
3067
-      "resolved": "https://registry.npmjs.org/hapi-swagger/-/hapi-swagger-14.1.3.tgz",
3068
-      "integrity": "sha512-Lb4LuJ4VCg/D4xeat/c9aMCpifuTKMgVC8taazB+Dn8evRRTyoymccGouk1H9VI35maV7F1dxzyZJ5ur+C2b/A==",
3066
+      "version": "14.2.5",
3067
+      "resolved": "https://registry.npmjs.org/hapi-swagger/-/hapi-swagger-14.2.5.tgz",
3068
+      "integrity": "sha512-rIxwCT9i+R9E9Z5m9BT15rwYI58IOKTKu7NEx9+pHO5aVeJK703qW3PWk72D7x9MSAnhmlJoEyUiFAU+6zQJ9A==",
3069 3069
       "requires": {
3070 3070
         "@hapi/boom": "^9.1.0",
3071 3071
         "@hapi/hoek": "^9.0.2",
3072
-        "handlebars": "^4.5.3",
3072
+        "handlebars": "^4.7.7",
3073 3073
         "http-status": "^1.0.1",
3074 3074
         "json-schema-ref-parser": "^6.1.0",
3075 3075
         "swagger-parser": "4.0.2",
3076
-        "swagger-ui-dist": "^3.47.1"
3076
+        "swagger-ui-dist": "^4.5.0"
3077 3077
       }
3078 3078
     },
3079 3079
     "has": {
@@ -4538,9 +4538,9 @@
4538 4538
       }
4539 4539
     },
4540 4540
     "objection": {
4541
-      "version": "2.2.15",
4542
-      "resolved": "https://registry.npmjs.org/objection/-/objection-2.2.15.tgz",
4543
-      "integrity": "sha512-ZOLJDigE9Z2ppk3C//S2fcWL6ph2jUe6Cwl0CEpslTZegnnOeG6RPIV80nhPAaghWjl/8F2kox/w89VVBN4ccg==",
4541
+      "version": "2.2.18",
4542
+      "resolved": "https://registry.npmjs.org/objection/-/objection-2.2.18.tgz",
4543
+      "integrity": "sha512-la7dWwKzpw+Sh4ROWWrZycq2k2z0IyYv3kb8rTPJPIRKuyV59DlSSctALPs5Feoi8I3RNxo3vnCuVoNcKgxthw==",
4544 4544
       "requires": {
4545 4545
         "ajv": "^6.12.6",
4546 4546
         "db-errors": "^0.2.3"
@@ -5848,9 +5848,9 @@
5848 5848
       "integrity": "sha1-cAcEaNbSl3ylI3suUZyn0Gouo/0="
5849 5849
     },
5850 5850
     "swagger-ui-dist": {
5851
-      "version": "3.49.0",
5852
-      "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.49.0.tgz",
5853
-      "integrity": "sha512-R1+eT16XNP1bBLfacISifZAkFJlpwvWsS2vVurF5pbIFZnmCasD/hj+9r/q7urYdQyb0B6v11mDnuYU7rUpfQg=="
5851
+      "version": "4.5.2",
5852
+      "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.5.2.tgz",
5853
+      "integrity": "sha512-wV4w54eW9z+VKbYJBJfULfqO05otCbM9jwgRIkwRl9CrfTVKelDzyhhEvdUQkGUzro+Ir8TOZPiZgKIdIdolWQ=="
5854 5854
     },
5855 5855
     "table": {
5856 5856
       "version": "6.7.1",
@@ -6002,9 +6002,9 @@
6002 6002
       }
6003 6003
     },
6004 6004
     "trim-off-newlines": {
6005
-      "version": "1.0.1",
6006
-      "resolved": "https://registry.npmjs.org/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz",
6007
-      "integrity": "sha1-n5up2e+odkw4dpi8v+sshI8RrbM=",
6005
+      "version": "1.0.3",
6006
+      "resolved": "https://registry.npmjs.org/trim-off-newlines/-/trim-off-newlines-1.0.3.tgz",
6007
+      "integrity": "sha512-kh6Tu6GbeSNMGfrrZh6Bb/4ZEHV1QlB4xNDBeog8Y9/QwFlKTRyWvY3Fs9tRDAMZliVUwieMgEdIeL/FtqjkJg==",
6008 6008
       "dev": true
6009 6009
     },
6010 6010
     "type-check": {
@@ -6038,9 +6038,9 @@
6038 6038
       }
6039 6039
     },
6040 6040
     "uglify-js": {
6041
-      "version": "3.13.7",
6042
-      "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.7.tgz",
6043
-      "integrity": "sha512-1Psi2MmnZJbnEsgJJIlfnd7tFlJfitusmR7zDI8lXlFI0ACD4/Rm/xdrU8bh6zF0i74aiVoBtkRiFulkrmh3AA==",
6041
+      "version": "3.15.1",
6042
+      "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.15.1.tgz",
6043
+      "integrity": "sha512-FAGKF12fWdkpvNJZENacOH0e/83eG6JyVQyanIJaBXCN1J11TUQv1T1/z8S+Z0CG0ZPk1nPcreF/c7lrTd0TEQ==",
6044 6044
       "optional": true
6045 6045
     },
6046 6046
     "unc-path-regex": {

+ 2
- 2
backend/package.json Просмотреть файл

@@ -26,12 +26,12 @@
26 26
     "compute-cosine-similarity": "^1.0.0",
27 27
     "dotenv": "^10.0.0",
28 28
     "exiting": "^6.0.1",
29
-    "hapi-swagger": "^14.1.3",
29
+    "hapi-swagger": "^14.2.5",
30 30
     "haversine": "^1.1.1",
31 31
     "joi": "^17.4.0",
32 32
     "knex": "^0.21.19",
33 33
     "mysql": "^2.18.1",
34
-    "objection": "^2.2.15",
34
+    "objection": "^2.2.18",
35 35
     "secure-password": "^4.0.0"
36 36
   },
37 37
   "devDependencies": {

+ 109
- 7
frontend/package-lock.json Просмотреть файл

@@ -1,8 +1,9 @@
1 1
 {
2 2
     "name": "vite-project",
3 3
     "version": "0.0.0",
4
-    "lockfileVersion": 2,
4
+    "lockfileVersion": 1,
5 5
     "requires": true,
6
+<<<<<<< HEAD
6 7
     "packages": {
7 8
         "": {
8 9
             "name": "vite-project",
@@ -5145,6 +5146,8 @@
5145 5146
             "dev": true
5146 5147
         }
5147 5148
     },
5149
+=======
5150
+>>>>>>> :sparkles: sse push updates!
5148 5151
     "dependencies": {
5149 5152
         "@babel/helper-validator-identifier": {
5150 5153
             "version": "7.15.7",
@@ -5175,11 +5178,18 @@
5175 5178
             "requires": {}
5176 5179
         },
5177 5180
         "@css-render/vue3-ssr": {
5181
+<<<<<<< HEAD
5178 5182
             "version": "0.15.9",
5179 5183
             "resolved": "https://registry.npmjs.org/@css-render/vue3-ssr/-/vue3-ssr-0.15.9.tgz",
5180 5184
             "integrity": "sha512-b3wvEIZYjToOEAV/oUqVtcg+MPF/iSZB9VmVF7fMAAAfvVTc2kB4TZDhGZCMkGjGZxOUm1jia7q/Z9FJnJGLKw==",
5181 5185
             "dev": true,
5182 5186
             "requires": {}
5187
+=======
5188
+            "version": "0.15.6",
5189
+            "resolved": "https://registry.npmjs.org/@css-render/vue3-ssr/-/vue3-ssr-0.15.6.tgz",
5190
+            "integrity": "sha512-aBb5tIezKlM7PycXoek/46oGO3kRg5Y+FgE3RGGKwvv8CAnLhdk5b3UM0LDIRfXdI+vxA/kSgk4pz9f7nDqGjA==",
5191
+            "dev": true
5192
+>>>>>>> :sparkles: sse push updates!
5183 5193
         },
5184 5194
         "@csstools/convert-colors": {
5185 5195
             "version": "1.4.0",
@@ -5331,11 +5341,18 @@
5331 5341
             "dev": true
5332 5342
         },
5333 5343
         "@vitejs/plugin-vue": {
5344
+<<<<<<< HEAD
5334 5345
             "version": "2.2.4",
5335 5346
             "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.2.4.tgz",
5336 5347
             "integrity": "sha512-ev9AOlp0ljCaDkFZF3JwC/pD2N4Hh+r5srl5JHM6BKg5+99jiiK0rE/XaRs3pVm1wzyKkjUy/StBSoXX5fFzcw==",
5337 5348
             "dev": true,
5338 5349
             "requires": {}
5350
+=======
5351
+            "version": "1.2.2",
5352
+            "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-1.2.2.tgz",
5353
+            "integrity": "sha512-5BI2WFfs/Z0pAV4S/IQf1oH3bmFYlL5ATMBHgTt1Lf7hAnfpNd5oUAAs6hZPfk3QhvyUQgtk0rJBlabwNFcBJQ==",
5354
+            "dev": true
5355
+>>>>>>> :sparkles: sse push updates!
5339 5356
         },
5340 5357
         "@vue/compiler-core": {
5341 5358
             "version": "3.2.31",
@@ -5462,8 +5479,7 @@
5462 5479
                     "version": "0.12.1",
5463 5480
                     "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.12.1.tgz",
5464 5481
                     "integrity": "sha512-QL3ny+wX8c6Xm1/EZylbgzdoDolye+VpCXRhI2hug9dJTP3OUJ3lmiKN3CsVV3mOJKwFi0nsstbgob0vG7aoIw==",
5465
-                    "dev": true,
5466
-                    "requires": {}
5482
+                    "dev": true
5467 5483
                 }
5468 5484
             }
5469 5485
         },
@@ -5480,8 +5496,7 @@
5480 5496
                     "version": "0.12.1",
5481 5497
                     "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.12.1.tgz",
5482 5498
                     "integrity": "sha512-QL3ny+wX8c6Xm1/EZylbgzdoDolye+VpCXRhI2hug9dJTP3OUJ3lmiKN3CsVV3mOJKwFi0nsstbgob0vG7aoIw==",
5483
-                    "dev": true,
5484
-                    "requires": {}
5499
+                    "dev": true
5485 5500
                 }
5486 5501
             }
5487 5502
         },
@@ -5495,8 +5510,7 @@
5495 5510
             "version": "5.3.2",
5496 5511
             "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz",
5497 5512
             "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
5498
-            "dev": true,
5499
-            "requires": {}
5513
+            "dev": true
5500 5514
         },
5501 5515
         "ajv": {
5502 5516
             "version": "6.12.6",
@@ -5884,11 +5898,18 @@
5884 5898
             "dev": true
5885 5899
         },
5886 5900
         "date-fns-tz": {
5901
+<<<<<<< HEAD
5887 5902
             "version": "1.3.0",
5888 5903
             "resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-1.3.0.tgz",
5889 5904
             "integrity": "sha512-r6ye6PmGEvkF467/41qzU71oGwv9kHTnV3vtSZdyV6VThwPID47ZH7FtR7zQWrhgOUWkYySm2ems2w6ZfNUqoA==",
5890 5905
             "dev": true,
5891 5906
             "requires": {}
5907
+=======
5908
+            "version": "1.1.6",
5909
+            "resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-1.1.6.tgz",
5910
+            "integrity": "sha512-nyy+URfFI3KUY7udEJozcoftju+KduaqkVfwyTIE0traBiVye09QnyWKLZK7drRr5h9B7sPJITmQnS3U6YOdQg==",
5911
+            "dev": true
5912
+>>>>>>> :sparkles: sse push updates!
5892 5913
         },
5893 5914
         "debug": {
5894 5915
             "version": "4.3.2",
@@ -6252,11 +6273,18 @@
6252 6273
             }
6253 6274
         },
6254 6275
         "eslint-config-prettier": {
6276
+<<<<<<< HEAD
6255 6277
             "version": "8.5.0",
6256 6278
             "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz",
6257 6279
             "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==",
6258 6280
             "dev": true,
6259 6281
             "requires": {}
6282
+=======
6283
+            "version": "8.3.0",
6284
+            "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz",
6285
+            "integrity": "sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==",
6286
+            "dev": true
6287
+>>>>>>> :sparkles: sse push updates!
6260 6288
         },
6261 6289
         "eslint-plugin-vue": {
6262 6290
             "version": "8.5.0",
@@ -6628,6 +6656,21 @@
6628 6656
                 "safer-buffer": ">= 2.1.2 < 3"
6629 6657
             }
6630 6658
         },
6659
+<<<<<<< HEAD
6660
+=======
6661
+        "icss-replace-symbols": {
6662
+            "version": "1.1.0",
6663
+            "resolved": "https://registry.npmjs.org/icss-replace-symbols/-/icss-replace-symbols-1.1.0.tgz",
6664
+            "integrity": "sha1-Bupvg2ead0njhs/h/oEq5dsiPe0=",
6665
+            "dev": true
6666
+        },
6667
+        "icss-utils": {
6668
+            "version": "5.1.0",
6669
+            "resolved": "https://registry.npmjs.org/icss-utils/-/icss-utils-5.1.0.tgz",
6670
+            "integrity": "sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==",
6671
+            "dev": true
6672
+        },
6673
+>>>>>>> :sparkles: sse push updates!
6631 6674
         "ignore": {
6632 6675
             "version": "5.2.0",
6633 6676
             "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz",
@@ -7070,7 +7113,12 @@
7070 7113
         "nanoid": {
7071 7114
             "version": "3.3.1",
7072 7115
             "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.1.tgz",
7116
+<<<<<<< HEAD
7073 7117
             "integrity": "sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw=="
7118
+=======
7119
+            "integrity": "sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw==",
7120
+            "dev": true
7121
+>>>>>>> :sparkles: sse push updates!
7074 7122
         },
7075 7123
         "natural-compare": {
7076 7124
             "version": "1.4.0",
@@ -7847,6 +7895,60 @@
7847 7895
                 }
7848 7896
             }
7849 7897
         },
7898
+<<<<<<< HEAD
7899
+=======
7900
+        "postcss-modules": {
7901
+            "version": "4.0.0",
7902
+            "resolved": "https://registry.npmjs.org/postcss-modules/-/postcss-modules-4.0.0.tgz",
7903
+            "integrity": "sha512-ghS/ovDzDqARm4Zj6L2ntadjyQMoyJmi0JkLlYtH2QFLrvNlxH5OAVRPWPeKilB0pY7SbuhO173KOWkPAxRJcw==",
7904
+            "dev": true,
7905
+            "requires": {
7906
+                "generic-names": "^2.0.1",
7907
+                "icss-replace-symbols": "^1.1.0",
7908
+                "lodash.camelcase": "^4.3.0",
7909
+                "postcss-modules-extract-imports": "^3.0.0",
7910
+                "postcss-modules-local-by-default": "^4.0.0",
7911
+                "postcss-modules-scope": "^3.0.0",
7912
+                "postcss-modules-values": "^4.0.0",
7913
+                "string-hash": "^1.1.1"
7914
+            }
7915
+        },
7916
+        "postcss-modules-extract-imports": {
7917
+            "version": "3.0.0",
7918
+            "resolved": "https://registry.npmjs.org/postcss-modules-extract-imports/-/postcss-modules-extract-imports-3.0.0.tgz",
7919
+            "integrity": "sha512-bdHleFnP3kZ4NYDhuGlVK+CMrQ/pqUm8bx/oGL93K6gVwiclvX5x0n76fYMKuIGKzlABOy13zsvqjb0f92TEXw==",
7920
+            "dev": true
7921
+        },
7922
+        "postcss-modules-local-by-default": {
7923
+            "version": "4.0.0",
7924
+            "resolved": "https://registry.npmjs.org/postcss-modules-local-by-default/-/postcss-modules-local-by-default-4.0.0.tgz",
7925
+            "integrity": "sha512-sT7ihtmGSF9yhm6ggikHdV0hlziDTX7oFoXtuVWeDd3hHObNkcHRo9V3yg7vCAY7cONyxJC/XXCmmiHHcvX7bQ==",
7926
+            "dev": true,
7927
+            "requires": {
7928
+                "icss-utils": "^5.0.0",
7929
+                "postcss-selector-parser": "^6.0.2",
7930
+                "postcss-value-parser": "^4.1.0"
7931
+            }
7932
+        },
7933
+        "postcss-modules-scope": {
7934
+            "version": "3.0.0",
7935
+            "resolved": "https://registry.npmjs.org/postcss-modules-scope/-/postcss-modules-scope-3.0.0.tgz",
7936
+            "integrity": "sha512-hncihwFA2yPath8oZ15PZqvWGkWf+XUfQgUGamS4LqoP1anQLOsOJw0vr7J7IwLpoY9fatA2qiGUGmuZL0Iqlg==",
7937
+            "dev": true,
7938
+            "requires": {
7939
+                "postcss-selector-parser": "^6.0.4"
7940
+            }
7941
+        },
7942
+        "postcss-modules-values": {
7943
+            "version": "4.0.0",
7944
+            "resolved": "https://registry.npmjs.org/postcss-modules-values/-/postcss-modules-values-4.0.0.tgz",
7945
+            "integrity": "sha512-RDxHkAiEGI78gS2ofyvCsu7iycRv7oqw5xMWn9iMoR0N/7mf9D50ecQqUo5BZ9Zh2vH4bCUR/ktCqbB9m8vJjQ==",
7946
+            "dev": true,
7947
+            "requires": {
7948
+                "icss-utils": "^5.0.0"
7949
+            }
7950
+        },
7951
+>>>>>>> :sparkles: sse push updates!
7850 7952
         "postcss-nested": {
7851 7953
             "version": "4.2.3",
7852 7954
             "resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-4.2.3.tgz",

+ 21
- 1
frontend/src/utils/db.js Просмотреть файл

@@ -72,4 +72,24 @@ class Connector {
72 72
     // async removeAll() { }
73 73
 }
74 74
 const db = new Connector()
75
-export { Connector, db }
75
+
76
+class Toaster {
77
+    constructor({ profileId }) {
78
+        this.url = `${remote}/notification/${profileId}/subscribe`
79
+        
80
+    }
81
+    connect() {
82
+        this.source = new EventSource(`${remote}/notification/${profileId}/subscribe`)
83
+        this.source.onmessage = e => {
84
+            console.log("Data", + e.data)
85
+        }
86
+        this.source.onerror = e => {
87
+            console.error("EventSource failed.", e)
88
+        }
89
+        this.source.addEventListener('end', e => {
90
+            this.close()
91
+        })
92
+    }
93
+}
94
+
95
+export { Connector, db, Toaster }

+ 27
- 0
frontend/src/views/home.vue Просмотреть файл

@@ -13,6 +13,7 @@ import sidebar from '../components/Sidebar.vue'
13 13
 import mainNav from '../components/MainNav.vue'
14 14
 import profileCardList from '../components/ProfileCardList.vue'
15 15
 import { fetchQueueByProfileId } from '../services'
16
+import { Toaster } from '../utils/db'
16 17
 
17 18
 import batch_10 from '../../../backend/db/generated/_batch_10.js.ref'
18 19
 import batch_20 from '../../../backend/db/generated/_batch_20.js.ref'
@@ -27,6 +28,20 @@ export default {
27 28
         mypid: null,
28 29
         loading: true
29 30
     }),
31
+    mounted() {
32
+        this.setupToaster()
33
+    },
34
+    async created() {
35
+        // this.mypid = auth.currentUser?.mypid || "99999";
36
+        this.mypid = 38
37
+        // Uncomment below to use for batch file data
38
+        // this.processProfilesFromBatch(this.parseBatch([batch_10, batch_20, batch_30]))
39
+
40
+        // Uncomment below to use API
41
+        const queueList = await fetchQueueByProfileId(this.mypid)
42
+        // console.log('queueList', queueList)
43
+        this.processQueue(queueList)
44
+    },
30 45
     methods: {
31 46
         setPid(pid) {
32 47
             this.mypid = pid
@@ -38,6 +53,18 @@ export default {
38 53
             this.processQueue(queueList)
39 54
             this.loading = false
40 55
         },
56
+        setupToaster() {
57
+            const stocks = {}
58
+            const source = new EventSource(`http://localhost:3001/api/notification/${this.mypid}/subscribe`)
59
+            source.addEventListener('stonk', function (message) {
60
+                console.log('updated:', message)
61
+                const data = JSON.parse(message.data)
62
+                stocks[data.name] = data
63
+            })
64
+            source.addEventListener('end', function (message) {
65
+                this.close()
66
+            })
67
+        },
41 68
         processQueue(queueList) {
42 69
             const formattedList = []
43 70
             queueList.forEach(profile => {

Загрузка…
Отмена
Сохранить