From ba56a7a7dceee32c5a2c9269d9c76cee8cf18236 Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Wed, 29 May 2024 13:46:08 -0700 Subject: [PATCH 01/14] Latest route changes (routes.ts) --- src/notification/subscribe/subscribe.ts | 4 +- src/routes/routes.ts | 80 ++++++++++++++++-- yarn.lock | 106 ++++++++++++++++++++++-- 3 files changed, 179 insertions(+), 11 deletions(-) diff --git a/src/notification/subscribe/subscribe.ts b/src/notification/subscribe/subscribe.ts index f2a1f7be..ccd6d655 100644 --- a/src/notification/subscribe/subscribe.ts +++ b/src/notification/subscribe/subscribe.ts @@ -65,4 +65,6 @@ client.on('message', async (receivedTopic, msg) => { console.error(error); } -}); \ No newline at end of file +}); + +export default client; \ No newline at end of file diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 31c097b6..6ea2282b 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,5 +1,7 @@ const express = require("express"); -const User = require("../models/UserSchema") +const User = require("../models/UserSchema"); +import publishToQueue from '../notification/publish/publish'; +import client from '../notification/subscribe/subscribe'; export const router = express.Router() @@ -20,6 +22,14 @@ router.post('/register', (req: any, res: any) => { }) // Get all method +router.get('/users', async (err: any, res: any) => { + try { + const users = await User.find(); + res.status(200).json(users); + } catch (err) { + res.status(500).json({ error: 'Failed to fetch users' }); + } +}); // Get one method router.post('/account', async (req: any, res: any) => { @@ -37,10 +47,70 @@ router.post('/account', async (req: any, res: any) => { }); }) -// Update one +// Update one user method +router.put('/users/:id', async (req: any, res: any) => { + try { + const updatedUser = await User.findByIdAndUpdate(req.params.id, req.body, { new: true }); + if (!updatedUser) { + return res.status(404).json({ error: 'User not found' }); + } + res.status(200).json(updatedUser); + } catch (err) { + res.status(500).json({ error: 'Failed to update user' }); + } +}); + +// Delete one user method +router.delete('/users/:id', async (req: any, res: any) => { + try { + const deletedUser = await User.findByIdAndDelete(req.params.id); + if (!deletedUser) { + return res.status(404).json({ error: 'User not found' }); + } + res.status(200).json({ message: 'User deleted' }); + } catch (err) { + res.status(500).json({ error: 'Failed to delete user' }); + } +}); -// Delete one +// Delete all users method +router.delete('/users', async (req: any, res: any) => { + try { + await User.deleteMany(); + res.status(200).json({ message: 'All users deleted' }); + } catch (err) { + res.status(500).json({ error: 'Failed to delete users' }); + } +}); -// Delete all -module.exports = router +// Route to publish a message to a queue +router.post('/publish', (req: any, res: any) => { + const { queueName, message } = req.body; + try { + publishToQueue(queueName, message); + res.status(200).json({ message: 'Message published' }); + } catch (error) { + res.status(500).json({ error: 'Failed to publish message' }); + } +}); + +// Route to subscribe to a queue +router.post('/subscribe', async (req: any, res: any) => { + const { queueName } = req.body; + try { + // Subscribe to the specified topic + client.subscribe(queueName, (error) => { + if (error) { + console.error("Failed to subscribe:", error); + res.status(500).json({ error: 'Failed to subscribe to queue' }); + } else { + res.status(200).json({ message: `Subscribed to queue ${queueName}` }); + } + }); + } catch (error) { + console.error("Failed to subscribe:", error); + res.status(500).json({ error: 'Failed to subscribe to queue' }); + } +}); +module.exports = router; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 5f117607..274a118f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1808,6 +1808,13 @@ resolved "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz" integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== +"@mongodb-js/saslprep@^1.1.0": + version "1.1.4" + resolved "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.4.tgz" + integrity sha512-8zJ8N1x51xo9hwPh6AWnKdLGEC5N3lDa6kms1YHmFBoRhTpJR6HG8wWk0td1MVCu9cD4YBrvjZEtd5Obw0Fbnw== + dependencies: + sparse-bitfield "^3.0.3" + "@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1": version "5.1.1-v1" resolved "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz" @@ -2385,6 +2392,18 @@ resolved "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz" integrity sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw== +"@types/webidl-conversions@*": + version "7.0.3" + resolved "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz" + integrity sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA== + +"@types/whatwg-url@^11.0.2": + version "11.0.4" + resolved "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.4.tgz" + integrity sha512-lXCmTWSHJvf0TRSO58nm978b8HJ/EdsSsEKLd3ODHFjo+3VGAyyTp4v50nWvwtzBxSMQrVOK7tcuN0zGPLICMw== + dependencies: + "@types/webidl-conversions" "*" + "@types/ws@^8.5.5": version "8.5.10" resolved "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz" @@ -3292,6 +3311,11 @@ bser@2.1.1: dependencies: node-int64 "^0.4.0" +bson@^6.2.0: + version "6.2.0" + resolved "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz" + integrity sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q== + buffer-from@^1.0.0: version "1.1.2" resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz" @@ -3948,7 +3972,7 @@ debug@^3.2.7: dependencies: ms "^2.1.1" -debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4, debug@4: +debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4, debug@4, debug@4.x: version "4.3.4" resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -6899,6 +6923,11 @@ jsonpointer@^5.0.0: object.assign "^4.1.4" object.values "^1.1.6" +kareem@2.5.1: + version "2.5.1" + resolved "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz" + integrity sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA== + keyboard-key@^1.0.4: version "1.1.0" resolved "https://registry.npmjs.org/keyboard-key/-/keyboard-key-1.1.0.tgz" @@ -7143,6 +7172,11 @@ memfs@^3.1.2, memfs@^3.4.3: dependencies: fs-monkey "^1.0.4" +memory-pager@^1.0.2: + version "1.5.0" + resolved "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz" + integrity sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg== + merge-descriptors@1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz" @@ -7238,9 +7272,27 @@ mkdirp@~0.5.1: dependencies: minimist "^1.2.6" -mongoose@*, "mongoose@file:../../usr/local/share/nvm/versions/node/v20.11.0/lib/node_modules/mongoose": - version "8.1.3" - resolved "file:../../usr/local/share/nvm/versions/node/v20.11.0/lib/node_modules/mongoose" +mongodb-connection-string-url@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.0.tgz" + integrity sha512-t1Vf+m1I5hC2M5RJx/7AtxgABy1cZmIPQRMXw+gEIPn/cZNF3Oiy+l0UIypUwVB5trcWHq3crg2g3uAR9aAwsQ== + dependencies: + "@types/whatwg-url" "^11.0.2" + whatwg-url "^13.0.0" + +mongodb@6.3.0: + version "6.3.0" + resolved "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz" + integrity sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA== + dependencies: + "@mongodb-js/saslprep" "^1.1.0" + bson "^6.2.0" + mongodb-connection-string-url "^3.0.0" + +mongoose@*, mongoose@^8.1.1: + version "8.1.1" + resolved "https://registry.npmjs.org/mongoose/-/mongoose-8.1.1.tgz" + integrity sha512-DbLb0NsiEXmaqLOpEz+AtAsgwhRw6f25gwa1dF5R7jj6lS1D8X6uTdhBSC8GDVtOwe5Tfw2EL7nTn6hiJT3Bgg== dependencies: bson "^6.2.0" kareem "2.5.1" @@ -7250,6 +7302,18 @@ mongoose@*, "mongoose@file:../../usr/local/share/nvm/versions/node/v20.11.0/lib/ ms "2.1.3" sift "16.0.1" +mpath@0.9.0: + version "0.9.0" + resolved "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz" + integrity sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew== + +mquery@5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz" + integrity sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg== + dependencies: + debug "4.x" + ms@^2.1.1, ms@2.1.2: version "2.1.2" resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz" @@ -8373,7 +8437,7 @@ psl@^1.1.33: resolved "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz" integrity sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag== -punycode@^2.1.0, punycode@^2.1.1: +punycode@^2.1.0, punycode@^2.1.1, punycode@^2.3.0: version "2.3.1" resolved "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz" integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg== @@ -9133,6 +9197,11 @@ side-channel@^1.0.4: get-intrinsic "^1.0.2" object-inspect "^1.9.0" +sift@16.0.1: + version "16.0.1" + resolved "https://registry.npmjs.org/sift/-/sift-16.0.1.tgz" + integrity sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ== + signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7: version "3.0.7" resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz" @@ -9219,6 +9288,13 @@ sourcemap-codec@^1.4.8: resolved "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz" integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== +sparse-bitfield@^3.0.3: + version "3.0.3" + resolved "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz" + integrity sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ== + dependencies: + memory-pager "^1.0.2" + spdy-transport@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/spdy-transport/-/spdy-transport-3.0.0.tgz" @@ -9683,6 +9759,13 @@ tr46@^2.1.0: dependencies: punycode "^2.1.1" +tr46@^4.1.1: + version "4.1.1" + resolved "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz" + integrity sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw== + dependencies: + punycode "^2.3.0" + tryer@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz" @@ -10077,6 +10160,11 @@ webidl-conversions@^6.1.0: resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz" integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w== +webidl-conversions@^7.0.0: + version "7.0.0" + resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz" + integrity sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g== + webpack-dev-middleware@^5.3.1: version "5.3.3" resolved "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz" @@ -10214,6 +10302,14 @@ whatwg-mimetype@^2.3.0: resolved "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz" integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g== +whatwg-url@^13.0.0: + version "13.0.0" + resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-13.0.0.tgz" + integrity sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig== + dependencies: + tr46 "^4.1.1" + webidl-conversions "^7.0.0" + whatwg-url@^7.0.0: version "7.1.0" resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz" From cfa7912a1f9ba2080dc520829c89b1c54f0c4817 Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Tue, 4 Jun 2024 12:39:30 -0700 Subject: [PATCH 02/14] export router from subscribe.ts and update routes.ts --- src/notification/subscribe/subscribe.ts | 2 +- src/routes/routes.ts | 85 ++++++++----------------- 2 files changed, 28 insertions(+), 59 deletions(-) diff --git a/src/notification/subscribe/subscribe.ts b/src/notification/subscribe/subscribe.ts index ccd6d655..d8e2fc8d 100644 --- a/src/notification/subscribe/subscribe.ts +++ b/src/notification/subscribe/subscribe.ts @@ -67,4 +67,4 @@ client.on('message', async (receivedTopic, msg) => { } }); -export default client; \ No newline at end of file +export default router; \ No newline at end of file diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 6ea2282b..3f7aee21 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,28 +1,28 @@ -const express = require("express"); +import express from "express"; const User = require("../models/UserSchema"); -import publishToQueue from '../notification/publish/publish'; -import client from '../notification/subscribe/subscribe'; +import publishRouter from '../notification/publish/publish'; +import subscribeRouter from '../notification/subscribe/subscribe'; -export const router = express.Router() +const router = express.Router(); // Register method router.post('/register', (req: any, res: any) => { const user = new User({ - email:req.body.email, - name:req.body.name - }) - user.save(function (err: any, res: any) { + email: req.body.email, + name: req.body.name + }); + user.save(function (err: any) { if (err) { - console.log(err) - } - else { - console.log(res) + console.log(err); + res.status(500).json({ error: 'Failed to register user' }); + } else { + res.status(201).json({ message: 'User registered successfully' }); } - }) -}) + }); +}); // Get all method -router.get('/users', async (err: any, res: any) => { +router.get('/users', async (req: any, res: any) => { try { const users = await User.find(); res.status(200).json(users); @@ -33,19 +33,14 @@ router.get('/users', async (err: any, res: any) => { // Get one method router.post('/account', async (req: any, res: any) => { - User.find({}, function(err: any, users: any) { - let loginIn = false - - // Check if one of the users in the db is already present - // If so set that equal to flag, if not then indicate the user isn't registered - users.forEach(function(user: any) { - if (req.body.email === user.email) - loginIn = true - }); - - res.send({'success' : loginIn}); - }); -}) + try { + const users = await User.find(); + const loginIn = users.some((user: any) => req.body.email === user.email); + res.status(200).json({ success: loginIn }); + } catch (err) { + res.status(500).json({ error: 'Failed to check account' }); + } +}); // Update one user method router.put('/users/:id', async (req: any, res: any) => { @@ -83,34 +78,8 @@ router.delete('/users', async (req: any, res: any) => { } }); -// Route to publish a message to a queue -router.post('/publish', (req: any, res: any) => { - const { queueName, message } = req.body; - try { - publishToQueue(queueName, message); - res.status(200).json({ message: 'Message published' }); - } catch (error) { - res.status(500).json({ error: 'Failed to publish message' }); - } -}); - -// Route to subscribe to a queue -router.post('/subscribe', async (req: any, res: any) => { - const { queueName } = req.body; - try { - // Subscribe to the specified topic - client.subscribe(queueName, (error) => { - if (error) { - console.error("Failed to subscribe:", error); - res.status(500).json({ error: 'Failed to subscribe to queue' }); - } else { - res.status(200).json({ message: `Subscribed to queue ${queueName}` }); - } - }); - } catch (error) { - console.error("Failed to subscribe:", error); - res.status(500).json({ error: 'Failed to subscribe to queue' }); - } -}); +// Mount the publish and subscribe routers +router.use('/publish', publishRouter); +router.use('/subscribe', subscribeRouter); -module.exports = router; \ No newline at end of file +module.exports = router; From beb7a5316a0a556455fe828a883b254c33a41a0d Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Thu, 6 Jun 2024 13:17:52 -0700 Subject: [PATCH 03/14] router created in subscribe.ts, routes.ts changes --- src/notification/subscribe/subscribe.ts | 7 ++++ src/routes/routes.ts | 44 ++++++++++++++++--------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/notification/subscribe/subscribe.ts b/src/notification/subscribe/subscribe.ts index d8e2fc8d..312f2755 100644 --- a/src/notification/subscribe/subscribe.ts +++ b/src/notification/subscribe/subscribe.ts @@ -5,6 +5,8 @@ import mongoose, { Schema, Document } from 'mongoose'; import dotenv from 'dotenv'; dotenv.config(); +const router = express.Router(); + const options = { username: process.env.ACTIVE_MQ_USERNAME, password: process.env.ACTIVE_MQ_PASSWORD, @@ -67,4 +69,9 @@ client.on('message', async (receivedTopic, msg) => { } }); +// Define a route to check subscription status (example) +router.get('/status', (req: any, res: any) => { + res.status(200).json({ message: 'Subscriber is running' }); +}); + export default router; \ No newline at end of file diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 3f7aee21..c74f4eed 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,5 +1,5 @@ -import express from "express"; -const User = require("../models/UserSchema"); +import express from 'express'; +const User = require('../models/UserSchema'); import publishRouter from '../notification/publish/publish'; import subscribeRouter from '../notification/subscribe/subscribe'; @@ -7,21 +7,33 @@ const router = express.Router(); // Register method router.post('/register', (req: any, res: any) => { + const { email, name, creationDate, lastUpdated, deletionDate, devicesLinked } = req.body; + + // Validate required fields + if (!email || !name || !creationDate || !lastUpdated) { + return res.status(400).json({ error: 'Missing required fields' }); + } + const user = new User({ - email: req.body.email, - name: req.body.name + email, + name, + creationDate: new Date(creationDate), + lastUpdated: new Date(lastUpdated), + deletionDate: deletionDate ? new Date(deletionDate) : undefined, + devicesLinked: devicesLinked || [], }); - user.save(function (err: any) { + + user.save((err: any) => { if (err) { console.log(err); - res.status(500).json({ error: 'Failed to register user' }); + return res.status(500).json({ error: 'Failed to register user' }); } else { - res.status(201).json({ message: 'User registered successfully' }); + return res.status(201).json({ message: 'User registered successfully' }); } }); }); -// Get all method +// Get all users method router.get('/users', async (req: any, res: any) => { try { const users = await User.find(); @@ -31,14 +43,16 @@ router.get('/users', async (req: any, res: any) => { } }); -// Get one method -router.post('/account', async (req: any, res: any) => { +// Get one user by ID method +router.get('/users/:id', async (req: any, res: any) => { try { - const users = await User.find(); - const loginIn = users.some((user: any) => req.body.email === user.email); - res.status(200).json({ success: loginIn }); + const user = await User.findById(req.params.id); + if (!user) { + return res.status(404).json({ error: 'User not found' }); + } + res.status(200).json(user); } catch (err) { - res.status(500).json({ error: 'Failed to check account' }); + res.status(500).json({ error: 'Failed to fetch user' }); } }); @@ -82,4 +96,4 @@ router.delete('/users', async (req: any, res: any) => { router.use('/publish', publishRouter); router.use('/subscribe', subscribeRouter); -module.exports = router; +export default router; From 02256f9f09f50deca33eddb396c6a7c1c2cb51d4 Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Wed, 19 Jun 2024 18:19:27 -0700 Subject: [PATCH 04/14] Update routeURLs import statement to point to routes.ts instead of account.ts --- src/server/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/server.ts b/src/server/server.ts index b104c963..ad117b25 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -2,7 +2,7 @@ const express = require('express') const app = express() const { MongoClient, ServerApiVersion } = require('mongodb'); const mongoose = require('mongoose') -const routeURLs = require('../account/account') +const routeURLs = require('../src/routes/routes') const cors = require('cors') const User = require("../models/UserSchema") From e061b1c9a7ffdb0c0769854f7424adfd280af02f Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Fri, 21 Jun 2024 20:30:52 -0700 Subject: [PATCH 05/14] controllers created, routers created, device and user schema updated, publish/subscribe.ts updated, routes/server.ts updated --- package-lock.json | 580 +++++++++++++++++++++++- package.json | 2 + src/controllers/publishController.ts | 139 ++++++ src/controllers/subscribeController.ts | 73 +++ src/controllers/userController.ts | 74 +++ src/models/DeviceSchema.ts | 90 ++-- src/models/UserSchema.ts | 70 +-- src/notification/publish/publish.ts | 210 +-------- src/notification/subscribe/subscribe.ts | 86 ++-- src/routers/publishRoutes.ts | 18 + src/routers/subscribeRoutes.ts | 8 + src/routers/userRoutes.ts | 12 + src/routes/routes.ts | 4 +- src/server/server.ts | 48 +- yarn.lock | 247 +++++++++- 15 files changed, 1304 insertions(+), 357 deletions(-) create mode 100644 src/controllers/publishController.ts create mode 100644 src/controllers/subscribeController.ts create mode 100644 src/controllers/userController.ts create mode 100644 src/routers/publishRoutes.ts create mode 100644 src/routers/subscribeRoutes.ts create mode 100644 src/routers/userRoutes.ts diff --git a/package-lock.json b/package-lock.json index c79f2499..88d05448 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@types/mqtt": "^2.5.0", + "@types/uuid": "^10.0.0", "dotenv": "^16.4.1", "express": "^4.18.2", "jest": "^29.7.0", @@ -2011,9 +2013,9 @@ "integrity": "sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==" }, "node_modules/@babel/runtime": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.2.tgz", - "integrity": "sha512-mM8eg4yl5D6i3lu2QKPuPH4FArvJ8KhTofbE7jwMUv9KX5mBvwPAqnV3MlyBNqdp9RyRKP6Yck8TrfYrPvX3bg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.7.tgz", + "integrity": "sha512-UwgBRMjJP+xv857DCngvqXI3Iq6J4v0wXmwc6sapg+zyhbwmQX67LUEFrkK5tbyJ30jGuG3ZvWpBiB9LCy1kWw==", "dependencies": { "regenerator-runtime": "^0.14.0" }, @@ -3644,6 +3646,15 @@ "mongoose": "*" } }, + "node_modules/@types/mqtt": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@types/mqtt/-/mqtt-2.5.0.tgz", + "integrity": "sha512-n+0/ErBin30j+UbhcHGK/STjHjh65k85WNR6NlUjRG0g9yctpF12pS+SOkwz0wmp+7momAo9Cyi4Wmvy8UsCQg==", + "deprecated": "This is a stub types definition for MQTT (https://github.com/mqttjs/MQTT.js). MQTT provides its own type definitions, so you don't need @types/mqtt installed!", + "dependencies": { + "mqtt": "*" + } + }, "node_modules/@types/node": { "version": "20.10.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.0.tgz", @@ -3685,6 +3696,20 @@ "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==" }, + "node_modules/@types/readable-stream": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.14.tgz", + "integrity": "sha512-xZn/AuUbCMShGsqH/ehZtGDwQtbx00M9rZ2ENLe4tOjFZ/JFeWMhEZkk2fEe1jAUqqEAURIkFJ7Az/go8mM1/w==", + "dependencies": { + "@types/node": "*", + "safe-buffer": "~5.1.1" + } + }, + "node_modules/@types/readable-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, "node_modules/@types/resolve": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", @@ -3748,6 +3773,11 @@ "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==" }, + "node_modules/@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==" + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -4241,6 +4271,17 @@ "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==" }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -4968,6 +5009,25 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -5004,6 +5064,32 @@ "node": ">=8" } }, + "node_modules/bl": { + "version": "6.0.13", + "resolved": "https://registry.npmjs.org/bl/-/bl-6.0.13.tgz", + "integrity": "sha512-tMncAcpsyjZgAVbVFupVIaB2xud13xxT59fdHkuszY2jdZkqIWfpQdmII1fOe3kOGAz0mNLTIHEm+KxpYsQKKg==", + "dependencies": { + "@types/readable-stream": "^4.0.0", + "buffer": "^6.0.3", + "inherits": "^2.0.4", + "readable-stream": "^4.2.0" + } + }, + "node_modules/bl/node_modules/readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -5152,6 +5238,29 @@ "node": ">=16.20.1" } }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -5523,6 +5632,11 @@ "node": ">= 12" } }, + "node_modules/commist": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/commist/-/commist-3.2.0.tgz", + "integrity": "sha512-4PIMoPniho+LqXmpS5d3NuGYncG6XWlkBSVGiWycL22dd42OYdUGil2CWuzklaJoNxyxUSpO4MKIBU94viWNAw==" + }, "node_modules/common-path-prefix": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/common-path-prefix/-/common-path-prefix-3.0.0.tgz", @@ -5592,6 +5706,20 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "node_modules/concat-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz", + "integrity": "sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==", + "engines": [ + "node >= 6.0" + ], + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.0.2", + "typedarray": "^0.0.6" + } + }, "node_modules/confusing-browser-globals": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz", @@ -7478,6 +7606,14 @@ "node": ">= 0.6" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -7641,6 +7777,18 @@ "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==" }, + "node_modules/fast-unique-numbers": { + "version": "8.0.13", + "resolved": "https://registry.npmjs.org/fast-unique-numbers/-/fast-unique-numbers-8.0.13.tgz", + "integrity": "sha512-7OnTFAVPefgw2eBJ1xj2PGGR9FwYzSUso9decayHgCDX4sJkHLdcsYTytTg+tYv+wKF3U8gJuSBz2jJpQV4u/g==", + "dependencies": { + "@babel/runtime": "^7.23.8", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.1.0" + } + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -8412,6 +8560,11 @@ "he": "bin/he" } }, + "node_modules/help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==" + }, "node_modules/hoopy": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz", @@ -8686,6 +8839,25 @@ "node": ">=4" } }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/ignore": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", @@ -10634,6 +10806,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-sdsl": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", + "integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -11423,6 +11604,71 @@ "node": ">=4.0.0" } }, + "node_modules/mqtt": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/mqtt/-/mqtt-5.7.2.tgz", + "integrity": "sha512-b5xIA9J/K1LTubSWKaNYYLxYIusQdip6o9/8bRWad2TelRr8xLifjQt+SnamDAwMp3O6NdvR9E8ae7VMuN02kg==", + "dependencies": { + "@types/readable-stream": "^4.0.5", + "@types/ws": "^8.5.9", + "commist": "^3.2.0", + "concat-stream": "^2.0.0", + "debug": "^4.3.4", + "help-me": "^5.0.0", + "lru-cache": "^10.0.1", + "minimist": "^1.2.8", + "mqtt": "^5.2.0", + "mqtt-packet": "^9.0.0", + "number-allocator": "^1.0.14", + "readable-stream": "^4.4.2", + "reinterval": "^1.1.0", + "rfdc": "^1.3.0", + "split2": "^4.2.0", + "worker-timers": "^7.1.4", + "ws": "^8.17.1" + }, + "bin": { + "mqtt": "build/bin/mqtt.js", + "mqtt_pub": "build/bin/pub.js", + "mqtt_sub": "build/bin/sub.js" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/mqtt-packet": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-9.0.0.tgz", + "integrity": "sha512-8v+HkX+fwbodsWAZIZTI074XIoxVBOmPeggQuDFCGg1SqNcC+uoRMWu7J6QlJPqIUIJXmjNYYHxBBLr1Y/Df4w==", + "dependencies": { + "bl": "^6.0.8", + "debug": "^4.3.4", + "process-nextick-args": "^2.0.1" + } + }, + "node_modules/mqtt/node_modules/lru-cache": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz", + "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==", + "engines": { + "node": "14 || >=16.14" + } + }, + "node_modules/mqtt/node_modules/readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/mquery": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", @@ -11636,6 +11882,15 @@ "url": "https://github.com/fb55/nth-check?sponsor=1" } }, + "node_modules/number-allocator": { + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/number-allocator/-/number-allocator-1.0.14.tgz", + "integrity": "sha512-OrL44UTVAvkKdOdRQZIJpLkAdjXGTRda052sN4sO77bKEzYYqWKMBjQvrJFzqygI99gL6Z4u2xctPW1tB8ErvA==", + "dependencies": { + "debug": "^4.3.1", + "js-sdsl": "4.3.0" + } + }, "node_modules/nwsapi": { "version": "2.2.7", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz", @@ -13426,6 +13681,14 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -15311,6 +15574,11 @@ "jsesc": "bin/jsesc" } }, + "node_modules/reinterval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reinterval/-/reinterval-1.1.0.tgz", + "integrity": "sha512-QIRet3SYrGp0HUHO88jVskiG6seqUGC5iAG7AwI/BV4ypGcuqk9Du6YQBUOUqm9c8pw1eyLoIaONifRua1lsEQ==" + }, "node_modules/relateurl": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz", @@ -15465,6 +15733,11 @@ "node": ">=0.10.0" } }, + "node_modules/rfdc": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==" + }, "node_modules/rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -16078,6 +16351,14 @@ "wbuf": "^1.7.3" } }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -17113,6 +17394,11 @@ "resolved": "https://registry.npmjs.org/typed-styles/-/typed-styles-0.0.7.tgz", "integrity": "sha512-pzP0PWoZUhsECYjABgCGQlRGL1n7tOHsgwYv3oIiEpJwGhFTuty/YNeduxQYzXXa3Ge5BdT6sHYIQYpl4uJ+5Q==" }, + "node_modules/typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" + }, "node_modules/typedarray-to-buffer": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", @@ -18166,6 +18452,37 @@ "workbox-core": "6.6.0" } }, + "node_modules/worker-timers": { + "version": "7.1.8", + "resolved": "https://registry.npmjs.org/worker-timers/-/worker-timers-7.1.8.tgz", + "integrity": "sha512-R54psRKYVLuzff7c1OTFcq/4Hue5Vlz4bFtNEIarpSiCYhpifHU3aIQI29S84o1j87ePCYqbmEJPqwBTf+3sfw==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2", + "worker-timers-broker": "^6.1.8", + "worker-timers-worker": "^7.0.71" + } + }, + "node_modules/worker-timers-broker": { + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/worker-timers-broker/-/worker-timers-broker-6.1.8.tgz", + "integrity": "sha512-FUCJu9jlK3A8WqLTKXM9E6kAmI/dR1vAJ8dHYLMisLNB/n3GuaFIjJ7pn16ZcD1zCOf7P6H62lWIEBi+yz/zQQ==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "fast-unique-numbers": "^8.0.13", + "tslib": "^2.6.2", + "worker-timers-worker": "^7.0.71" + } + }, + "node_modules/worker-timers-worker": { + "version": "7.0.71", + "resolved": "https://registry.npmjs.org/worker-timers-worker/-/worker-timers-worker-7.0.71.tgz", + "integrity": "sha512-ks/5YKwZsto1c2vmljroppOKCivB/ma97g9y77MAAz2TBBjPPgpoOiS1qYQKIgvGTr2QYPT3XhJWIB6Rj2MVPQ==", + "dependencies": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2" + } + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -18200,9 +18517,9 @@ } }, "node_modules/ws": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz", - "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, @@ -19614,9 +19931,9 @@ "integrity": "sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==" }, "@babel/runtime": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.2.tgz", - "integrity": "sha512-mM8eg4yl5D6i3lu2QKPuPH4FArvJ8KhTofbE7jwMUv9KX5mBvwPAqnV3MlyBNqdp9RyRKP6Yck8TrfYrPvX3bg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.7.tgz", + "integrity": "sha512-UwgBRMjJP+xv857DCngvqXI3Iq6J4v0wXmwc6sapg+zyhbwmQX67LUEFrkK5tbyJ30jGuG3ZvWpBiB9LCy1kWw==", "requires": { "regenerator-runtime": "^0.14.0" } @@ -20756,6 +21073,14 @@ "mongoose": "*" } }, + "@types/mqtt": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@types/mqtt/-/mqtt-2.5.0.tgz", + "integrity": "sha512-n+0/ErBin30j+UbhcHGK/STjHjh65k85WNR6NlUjRG0g9yctpF12pS+SOkwz0wmp+7momAo9Cyi4Wmvy8UsCQg==", + "requires": { + "mqtt": "*" + } + }, "@types/node": { "version": "20.10.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.0.tgz", @@ -20797,6 +21122,22 @@ "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==" }, + "@types/readable-stream": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.14.tgz", + "integrity": "sha512-xZn/AuUbCMShGsqH/ehZtGDwQtbx00M9rZ2ENLe4tOjFZ/JFeWMhEZkk2fEe1jAUqqEAURIkFJ7Az/go8mM1/w==", + "requires": { + "@types/node": "*", + "safe-buffer": "~5.1.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + } + } + }, "@types/resolve": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", @@ -20860,6 +21201,11 @@ "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==" }, + "@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==" + }, "@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -21227,6 +21573,14 @@ "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==" }, + "abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "requires": { + "event-target-shim": "^5.0.0" + } + }, "accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -21753,6 +22107,11 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + }, "batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -21780,6 +22139,31 @@ "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==" }, + "bl": { + "version": "6.0.13", + "resolved": "https://registry.npmjs.org/bl/-/bl-6.0.13.tgz", + "integrity": "sha512-tMncAcpsyjZgAVbVFupVIaB2xud13xxT59fdHkuszY2jdZkqIWfpQdmII1fOe3kOGAz0mNLTIHEm+KxpYsQKKg==", + "requires": { + "@types/readable-stream": "^4.0.0", + "buffer": "^6.0.3", + "inherits": "^2.0.4", + "readable-stream": "^4.2.0" + }, + "dependencies": { + "readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "requires": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + } + } + } + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -21894,6 +22278,15 @@ "resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz", "integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==" }, + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -22157,6 +22550,11 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==" }, + "commist": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/commist/-/commist-3.2.0.tgz", + "integrity": "sha512-4PIMoPniho+LqXmpS5d3NuGYncG6XWlkBSVGiWycL22dd42OYdUGil2CWuzklaJoNxyxUSpO4MKIBU94viWNAw==" + }, "common-path-prefix": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/common-path-prefix/-/common-path-prefix-3.0.0.tgz", @@ -22219,6 +22617,17 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "concat-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz", + "integrity": "sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==", + "requires": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.0.2", + "typedarray": "^0.0.6" + } + }, "confusing-browser-globals": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz", @@ -23556,6 +23965,11 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==" }, + "event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" + }, "eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -23699,6 +24113,15 @@ "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==" }, + "fast-unique-numbers": { + "version": "8.0.13", + "resolved": "https://registry.npmjs.org/fast-unique-numbers/-/fast-unique-numbers-8.0.13.tgz", + "integrity": "sha512-7OnTFAVPefgw2eBJ1xj2PGGR9FwYzSUso9decayHgCDX4sJkHLdcsYTytTg+tYv+wKF3U8gJuSBz2jJpQV4u/g==", + "requires": { + "@babel/runtime": "^7.23.8", + "tslib": "^2.6.2" + } + }, "fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -24240,6 +24663,11 @@ "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" }, + "help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==" + }, "hoopy": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz", @@ -24440,6 +24868,11 @@ "harmony-reflect": "^1.4.6" } }, + "ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + }, "ignore": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz", @@ -25894,6 +26327,11 @@ "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz", "integrity": "sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==" }, + "js-sdsl": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", + "integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==" + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -26463,6 +26901,59 @@ "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==" }, + "mqtt": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/mqtt/-/mqtt-5.7.2.tgz", + "integrity": "sha512-b5xIA9J/K1LTubSWKaNYYLxYIusQdip6o9/8bRWad2TelRr8xLifjQt+SnamDAwMp3O6NdvR9E8ae7VMuN02kg==", + "requires": { + "@types/readable-stream": "^4.0.5", + "@types/ws": "^8.5.9", + "commist": "^3.2.0", + "concat-stream": "^2.0.0", + "debug": "^4.3.4", + "help-me": "^5.0.0", + "lru-cache": "^10.0.1", + "minimist": "^1.2.8", + "mqtt": "^5.2.0", + "mqtt-packet": "^9.0.0", + "number-allocator": "^1.0.14", + "readable-stream": "^4.4.2", + "reinterval": "^1.1.0", + "rfdc": "^1.3.0", + "split2": "^4.2.0", + "worker-timers": "^7.1.4", + "ws": "^8.17.1" + }, + "dependencies": { + "lru-cache": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz", + "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==" + }, + "readable-stream": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", + "requires": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + } + } + } + }, + "mqtt-packet": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-9.0.0.tgz", + "integrity": "sha512-8v+HkX+fwbodsWAZIZTI074XIoxVBOmPeggQuDFCGg1SqNcC+uoRMWu7J6QlJPqIUIJXmjNYYHxBBLr1Y/Df4w==", + "requires": { + "bl": "^6.0.8", + "debug": "^4.3.4", + "process-nextick-args": "^2.0.1" + } + }, "mquery": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", @@ -26624,6 +27115,15 @@ "boolbase": "^1.0.0" } }, + "number-allocator": { + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/number-allocator/-/number-allocator-1.0.14.tgz", + "integrity": "sha512-OrL44UTVAvkKdOdRQZIJpLkAdjXGTRda052sN4sO77bKEzYYqWKMBjQvrJFzqygI99gL6Z4u2xctPW1tB8ErvA==", + "requires": { + "debug": "^4.3.1", + "js-sdsl": "4.3.0" + } + }, "nwsapi": { "version": "2.2.7", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz", @@ -27716,6 +28216,11 @@ } } }, + "process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==" + }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -29161,6 +29666,11 @@ } } }, + "reinterval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reinterval/-/reinterval-1.1.0.tgz", + "integrity": "sha512-QIRet3SYrGp0HUHO88jVskiG6seqUGC5iAG7AwI/BV4ypGcuqk9Du6YQBUOUqm9c8pw1eyLoIaONifRua1lsEQ==" + }, "relateurl": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz", @@ -29264,6 +29774,11 @@ "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==" }, + "rfdc": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==" + }, "rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -29722,6 +30237,11 @@ "wbuf": "^1.7.3" } }, + "split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==" + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -30491,6 +31011,11 @@ "resolved": "https://registry.npmjs.org/typed-styles/-/typed-styles-0.0.7.tgz", "integrity": "sha512-pzP0PWoZUhsECYjABgCGQlRGL1n7tOHsgwYv3oIiEpJwGhFTuty/YNeduxQYzXXa3Ge5BdT6sHYIQYpl4uJ+5Q==" }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" + }, "typedarray-to-buffer": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", @@ -31314,6 +31839,37 @@ "workbox-core": "6.6.0" } }, + "worker-timers": { + "version": "7.1.8", + "resolved": "https://registry.npmjs.org/worker-timers/-/worker-timers-7.1.8.tgz", + "integrity": "sha512-R54psRKYVLuzff7c1OTFcq/4Hue5Vlz4bFtNEIarpSiCYhpifHU3aIQI29S84o1j87ePCYqbmEJPqwBTf+3sfw==", + "requires": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2", + "worker-timers-broker": "^6.1.8", + "worker-timers-worker": "^7.0.71" + } + }, + "worker-timers-broker": { + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/worker-timers-broker/-/worker-timers-broker-6.1.8.tgz", + "integrity": "sha512-FUCJu9jlK3A8WqLTKXM9E6kAmI/dR1vAJ8dHYLMisLNB/n3GuaFIjJ7pn16ZcD1zCOf7P6H62lWIEBi+yz/zQQ==", + "requires": { + "@babel/runtime": "^7.24.5", + "fast-unique-numbers": "^8.0.13", + "tslib": "^2.6.2", + "worker-timers-worker": "^7.0.71" + } + }, + "worker-timers-worker": { + "version": "7.0.71", + "resolved": "https://registry.npmjs.org/worker-timers-worker/-/worker-timers-worker-7.0.71.tgz", + "integrity": "sha512-ks/5YKwZsto1c2vmljroppOKCivB/ma97g9y77MAAz2TBBjPPgpoOiS1qYQKIgvGTr2QYPT3XhJWIB6Rj2MVPQ==", + "requires": { + "@babel/runtime": "^7.24.5", + "tslib": "^2.6.2" + } + }, "wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -31339,9 +31895,9 @@ } }, "ws": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz", - "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "requires": {} }, "xml-name-validator": { diff --git a/package.json b/package.json index b1621741..889e98d7 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "author": "", "license": "ISC", "dependencies": { + "@types/mqtt": "^2.5.0", + "@types/uuid": "^10.0.0", "dotenv": "^16.4.1", "express": "^4.18.2", "jest": "^29.7.0", diff --git a/src/controllers/publishController.ts b/src/controllers/publishController.ts new file mode 100644 index 00000000..96f4abf7 --- /dev/null +++ b/src/controllers/publishController.ts @@ -0,0 +1,139 @@ +import { Request, Response } from 'express'; +import mqtt, { MqttClient } from 'mqtt'; +import { v1 as uuidv1 } from 'uuid'; +import mongoose from 'mongoose'; +import dotenv from 'dotenv'; +dotenv.config(); +import db from '../notification/publish/db'; // Import the db.ts file to access the dbURI variable +import Device from '../models/DeviceSchema'; // Import Device model +import User from '../models/UserSchema'; // Import User model + +const options = { + username: process.env.ACTIVE_MQ_USERNAME, + password: process.env.ACTIVE_MQ_PASSWORD, + clientId: `publish_${uuidv1()}`, + port: 1883, +}; +const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion + +// Establish Mongoose connection +mongoose.connect(db.dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, +} as mongoose.ConnectOptions).then(() => { + console.log('MongoDB connected'); +}).catch((error) => { + console.error('MongoDB connection error:', error); +}); + +// Register account +export const registerAccount = async (req: Request, res: Response) => { + try { + const { email, name, deletionDate, devicesLinked } = req.body; + const currentDate = new Date(); // Set current timestamp + const newAccountData = { + email, + name, + creationDate: currentDate, + lastUpdated: currentDate, + deletionDate: deletionDate ? new Date(deletionDate) : null, + }; + + const newAccount = new User(newAccountData); + + // Handle devicesLinked + if (devicesLinked && devicesLinked.length > 0) { + const devices = await Device.insertMany(devicesLinked); // Use Device to refer to the Device model + newAccount.devicesLinked = devices.map((device: any) => device._id); // Use explicit typing or adjust as needed + } else { + newAccount.devicesLinked = []; + } + + const savedAccount = await newAccount.save(); // Save the new account to the database + res.status(201).json(savedAccount); // HTTP 201 Created status code for successful creation + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +// Get all accounts +export const getAllAccounts = async (_req: Request, res: Response) => { + try { + const events = await User.find(); // Use User model + res.json(events); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +// Get account by ID +export const getAccountById = async (req: Request, res: Response) => { + try { + const event = await User.findById(req.params.id); // Use User model + + if (!event) { + res.status(404).json({ error: 'Event not found' }); + return; + } + + if (!req.params.id) { + res.status(400).json({ error: 'Bad Request' }); + return; + } + + res.json(event); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +// Delete account by ID +export const deleteAccountById = async (req: Request, res: Response) => { + try { + const events = await User.findByIdAndDelete(req.params.id); // Use User model + + if (!events) { + // If the document doesn't exist, return a 404 Not Found response + res.status(404).json({ error: 'Event not found' }); + return; + } + + // If the document is successfully deleted, return a success message + res.json({ message: 'Event deleted successfully' }); + } catch (error) { + // If an error occurs during deletion, return a 500 Internal Server Error response + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +// Publish message to MQTT +export const publishMessage = async (req: Request, res: Response) => { + const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); + + const event = { + id: req.params.id, + message: "From Publish Service", + }; + + client.on('connect', () => { + console.log("Broker connected"); + client.publish(topic, JSON.stringify(event), {}, (err) => { + if (err) { + console.error(`Error publishing message: ${err}`); + res.status(500).json({ error: 'Internal Server Error' }); + } else { + client.end(); + res.json(event); + } + }); + }); + + client.on('error', (error) => { + console.log(error); + res.status(500).json({ error: 'Internal Server Error' }); + }); +}; diff --git a/src/controllers/subscribeController.ts b/src/controllers/subscribeController.ts new file mode 100644 index 00000000..9ebb51b5 --- /dev/null +++ b/src/controllers/subscribeController.ts @@ -0,0 +1,73 @@ +import { Request, Response } from 'express'; +import mqtt, { MqttClient } from 'mqtt'; +import { v1 as uuidv1 } from 'uuid'; +import mongoose, { Schema, Document } from 'mongoose'; +import dotenv from 'dotenv'; +dotenv.config(); + +const options = { + username: process.env.ACTIVE_MQ_USERNAME, + password: process.env.ACTIVE_MQ_PASSWORD, + clientId: `subscribe_${uuidv1()}`, + port: 1883, +}; + +const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion +const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); // Type assertion + +client.on('connect', () => { + client.subscribe(topic); +}); + +let message: string | null = null; + +client.on('message', async (receivedTopic, msg) => { + console.log(`Message received on topic ${receivedTopic}`); + message = msg.toString(); + console.log(`Message received: ${message}`); + + // MongoDB logic for handling received message + try { + interface Subscription extends Document { + id: string; + message: string; + } + + const subscriptionSchema = new Schema({ + id: String, + message: String, + }); + + const SubscriptionModel = mongoose.model('Subscription', subscriptionSchema); + + const subscription = { + id: uuidv1(), + message: message, + }; + + await SubscriptionModel.create(subscription); + } catch (error) { + + // Simulate a 404 error + if (!message) { + throw { status: 404, message: 'Not Found' }; + } + + // Simulate a 403 error + if (message === 'Forbidden') { + throw { status: 403, message: 'Forbidden' }; + } + + // Simulate a 401 error + if (message === 'Unauthorized') { + throw { status: 401, message: 'Unauthorized' }; + } + + console.error(error); + } +}); + +// Check subscription status +export const checkSubscriptionStatus = (req: Request, res: Response) => { + res.status(200).json({ message: 'Subscriber is running' }); +}; diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts new file mode 100644 index 00000000..efd31f8d --- /dev/null +++ b/src/controllers/userController.ts @@ -0,0 +1,74 @@ +import { Request, Response } from 'express'; +import Device, { DeviceInterface } from '../models/DeviceSchema'; // Import Device and DeviceInterface +import User, { UserInterface } from '../models/UserSchema'; // Import User and UserInterface + +// Controller to handle user registration +export const registerUser = async (req: Request, res: Response): Promise => { + try { + const { email, name, deletionDate, devicesLinked } = req.body; + const currentDate = new Date(); + + const newUser: UserInterface = new User({ + email, + name, + creationDate: currentDate, + lastUpdated: currentDate, + deletionDate: deletionDate ? new Date(deletionDate) : null, + devicesLinked: [], // Initialize as an empty array + }); + + if (devicesLinked && devicesLinked.length > 0) { + // Assuming devicesLinked is an array of objects that match DeviceInterface + const devices: any[] = await Device.insertMany(devicesLinked); // Cast to any[] temporarily + newUser.devicesLinked = devices.map((device: any) => device._id); // Map to _id + } + + const savedUser: UserInterface = await newUser.save(); + res.status(201).json(savedUser); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export const getAllUsers = async (_req: Request, res: Response): Promise => { + try { + const users: UserInterface[] = await User.find().populate('devicesLinked'); + res.json(users); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export const getUserById = async (req: Request, res: Response): Promise => { + try { + const user: UserInterface | null = await User.findById(req.params.id).populate('devicesLinked'); + + if (!user) { + res.status(404).json({ error: 'User not found' }); + return; + } + + res.json(user); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export const deleteUserById = async (req: Request, res: Response): Promise => { + try { + const deletedUser: UserInterface | null = await User.findByIdAndDelete(req.params.id); + + if (!deletedUser) { + res.status(404).json({ error: 'User not found' }); + return; + } + + res.json({ message: 'User deleted successfully' }); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; diff --git a/src/models/DeviceSchema.ts b/src/models/DeviceSchema.ts index f798f331..7c07f65f 100644 --- a/src/models/DeviceSchema.ts +++ b/src/models/DeviceSchema.ts @@ -1,41 +1,55 @@ -import mongoose from 'mongoose'; +import mongoose, { Schema, Document } from 'mongoose'; -const DeviceSchema = new mongoose.Schema({ - uuid: { - type: String, - unique: true - }, - lastUpdated: { - type: Date, - default: new Date(), - required: true - }, - powered: { - type: Boolean - }, - poweredTimestamp: { - type: Date - }, - connected: { - type: Boolean - }, - connectedTimestamp: { - type: Date - }, - color: { - type: String - }, - colorTimestamp: { - type: String - }, - brightness: { - type: Number - }, - brightnessTimestamp:{ - type: Date - } -}) +export interface DeviceInterface extends Document { + uuid: string; + lastUpdated: Date; + powered?: boolean; + poweredTimestamp?: Date | null; + connected?: boolean; + connectedTimestamp?: Date | null; + color?: string; + colorTimestamp?: string; + brightness?: number; + brightnessTimestamp?: Date | null; +} -const Device = mongoose.model("Device", DeviceSchema); +const DeviceSchema: Schema = new mongoose.Schema({ + uuid: { + type: String, + unique: true, + required: true, + }, + lastUpdated: { + type: Date, + default: new Date(), + required: true, + }, + powered: { + type: Boolean, + }, + poweredTimestamp: { + type: Date, + }, + connected: { + type: Boolean, + }, + connectedTimestamp: { + type: Date, + }, + color: { + type: String, + }, + colorTimestamp: { + type: String, + }, + brightness: { + type: Number, + }, + brightnessTimestamp: { + type: Date, + }, +}); -module.exports = Device; \ No newline at end of file +const Device = mongoose.model('Device', DeviceSchema); + +export default Device; // Export Device as default diff --git a/src/models/UserSchema.ts b/src/models/UserSchema.ts index 78842fe4..71e31561 100644 --- a/src/models/UserSchema.ts +++ b/src/models/UserSchema.ts @@ -1,33 +1,43 @@ -import mongoose, { Schema } from 'mongoose'; +import mongoose, { Schema, Document } from 'mongoose'; +import { DeviceInterface } from './DeviceSchema'; // Import DeviceInterface -export const UserSchema = new mongoose.Schema({ - - creationDate:{ - type: Date, - default: Date.now() - }, - deletionDate:{ - type: Date, - default: null - }, - lastUpdated:{ - type: Date, - default: Date.now(), - required: true - }, - email: { - type: String, - unique: true - }, - name: { - type: String - }, - devicesLinked: [{ - type: Schema.Types.ObjectId, - ref: 'Device', - }] -}) +export interface UserInterface extends Document { + creationDate: Date; + deletionDate: Date | null; + lastUpdated: Date; + email: string; + name?: string; + devicesLinked: mongoose.Types.ObjectId[] | DeviceInterface[]; // Adjust type to handle populated documents +} -export const User = mongoose.model("Account", UserSchema) +const UserSchema: Schema = new mongoose.Schema({ + creationDate: { + type: Date, + default: Date.now(), + }, + deletionDate: { + type: Date, + default: null, + }, + lastUpdated: { + type: Date, + default: Date.now(), + required: true, + }, + email: { + type: String, + unique: true, + required: true, + }, + name: { + type: String, + }, + devicesLinked: [{ + type: Schema.Types.ObjectId, + ref: 'Device', + }], +}); -module.exports = User; \ No newline at end of file +const User = mongoose.model('User', UserSchema); + +export default User; diff --git a/src/notification/publish/publish.ts b/src/notification/publish/publish.ts index 50670603..89b98ca4 100644 --- a/src/notification/publish/publish.ts +++ b/src/notification/publish/publish.ts @@ -1,13 +1,10 @@ -import express from 'express'; import mqtt, { MqttClient } from 'mqtt'; import { v1 as uuidv1 } from 'uuid'; -import mongoose, { Schema, Document, ConnectOptions } from 'mongoose'; import dotenv from 'dotenv'; -dotenv.config(); -import db from './db'; // Import the db.ts file to access the dbURI variable +import express from 'express'; +dotenv.config(); -const server = express(); const options = { username: process.env.ACTIVE_MQ_USERNAME, password: process.env.ACTIVE_MQ_PASSWORD, @@ -15,195 +12,34 @@ const options = { port: 1883, }; const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion -server.use(express.json()); -// MongoDB event schema and model -// Define Device schema -interface Device extends Document { - uuid: string; - lastUpdated: Date; - powered?: boolean; - poweredTimestamp?: Date; - connected?: boolean; - connectedTimestamp?: Date; - color?: string; - colorTimestamp?: Date; - brightness?: number; - brightnessTimestamp?: Date; -} +const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); -const deviceSchema = new Schema({ - uuid: { - type: String, - unique: true, - }, - lastUpdated: { - type: Date, - default: Date.now, - required: true, - }, - powered: Boolean, - poweredTimestamp: Date, - connected: Boolean, - connectedTimestamp: Date, - color: String, - colorTimestamp: Date, - brightness: Number, - brightnessTimestamp: Date, +client.on('connect', () => { + console.log("Broker connected"); }); -const DeviceModel = mongoose.model('Device', deviceSchema); - -// MongoDB event schema and model -interface DeviceLinked extends Document { - device: typeof DeviceModel; -} - -interface accounts extends Document { - creationDate: Date; - deletionDate?: Date; - lastUpdated: Date; - email: string; - name: string; - devicesLinked?: DeviceLinked[]; -} - -const accountSchema = new Schema({ - creationDate: { type: Date, required: true }, - deletionDate: { type: Date }, - lastUpdated: { type: Date, required: true }, - email: { type: String, required: true }, - name: { type: String, required: true }, - devicesLinked: [{ type: Schema.Types.ObjectId, ref: 'Device' }], +client.on('error', (error) => { + console.error(error); }); -// Establish Mongoose connection -mongoose.connect(db.dbURI, { - useNewUrlParser: true, - useUnifiedTopology: true, -} as ConnectOptions) -.then(() => { - console.log('MongoDB connected'); - - // Define Mongoose model after connection is established - const EventModel = mongoose.model('accounts', accountSchema); - - // Define routes and other server logic after the connection is established - - server.get("/publish/accounts/all", async (_req, res) => { - try { - const events = await EventModel.find(); - res.json(events); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } - }); - - server.get("/publish/accounts/:id", async (req, res) => { - try { - const event = await EventModel.findById(req.params.id); - - if (!event) { - res.status(404).json({ error: 'Event not found' }); - return; - } - - if (!req.params.id) { - res.status(400).json({ error: 'Bad Request' }); - return; - } - - res.json(event); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } - }); - - server.post("/publish/accounts/new", async (req, res) => { - try { - const { email, name, deletionDate, devicesLinked } = req.body; - const currentDate = new Date(); // Set current timestamp - const newAccountData = { - email, - name, - creationDate: currentDate, - lastUpdated: currentDate, - deletionDate: deletionDate ? new Date(deletionDate) : null, - }; - - const newAccount = new EventModel(newAccountData); - - // Handle devicesLinked - if (devicesLinked && devicesLinked.length > 0) { - const devices = await DeviceModel.insertMany(devicesLinked); - newAccount.devicesLinked = devices.map(device => device._id); - } else { - newAccount.devicesLinked = []; // Set devicesLinked to null if not received - } - - const savedAccount = await newAccount.save(); // Save the new account to the database - res.status(201).json(savedAccount); // HTTP 201 Created status code for successful creation - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } - }); - - server.delete("/publish/accounts/:id/delete", async (req, res) => { - try { - const events = await EventModel.findByIdAndDelete(req.params.id); - - if (!events) { - // If the document doesn't exist, return a 404 Not Found response - res.status(404).json({ error: 'Event not found' }); - return; - } - - // If the document is successfully deleted, return a success message - res.json({ message: 'Event deleted successfully' }); - } catch (error) { - // If an error occurs during deletion, return a 500 Internal Server Error response - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); +const publishRouter = express.Router(); + +publishRouter.post('/publish', (req, res) => { + const event = { + id: uuidv1(), + message: "Hello from Publish Service", + }; + + client.publish(topic, JSON.stringify(event), {}, (err) => { + if (err) { + console.error(`Error publishing message: ${err}`); + res.status(500).json({ error: 'Failed to publish message' }); + } else { + console.log(`Published message: ${JSON.stringify(event)} to topic ${topic}`); + res.status(200).json({ message: 'Message published successfully' }); } }); - - - server.get("/publish/:id", async (req, res) => { - const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); - - const event = { - id: req.params.id, - message: "From Publish Service", - }; - - client.on('connect', () => { - console.log("Broker connected"); - client.publish(topic, JSON.stringify(event), {}, (err) => { - if (err) { - console.error(`Error publishing message: ${err}`); - res.status(500).json({ error: 'Internal Server Error' }); - } else { - client.end(); - res.json(event); - } - }); - }); - - client.on('error', (error) => { - console.log(error); - res.status(500).json({ error: 'Internal Server Error' }); - }); - }); - - server.listen(4000, () => { - console.log("Server connected"); - }); -}) -.catch((error) => { - console.error('MongoDB connection error:', error); }); -export default server; \ No newline at end of file +export { publishRouter }; diff --git a/src/notification/subscribe/subscribe.ts b/src/notification/subscribe/subscribe.ts index 312f2755..172cd009 100644 --- a/src/notification/subscribe/subscribe.ts +++ b/src/notification/subscribe/subscribe.ts @@ -1,77 +1,45 @@ -import express from 'express'; import mqtt, { MqttClient } from 'mqtt'; -import { v1 as uuidv1 } from 'uuid'; -import mongoose, { Schema, Document } from 'mongoose'; import dotenv from 'dotenv'; -dotenv.config(); +import express from 'express'; -const router = express.Router(); +dotenv.config(); const options = { username: process.env.ACTIVE_MQ_USERNAME, password: process.env.ACTIVE_MQ_PASSWORD, - clientId: `subscribe_${uuidv1()}`, + clientId: `subscribe_${Math.random().toString(16).substr(2, 8)}`, // Generate random client ID port: 1883, }; - const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion -const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); // Type assertion - -client.on('connect', () => { - client.subscribe(topic); -}); - -let message: string | null = null; - -client.on('message', async (receivedTopic, msg) => { - console.log(`Message received on topic ${receivedTopic}`); - message = msg.toString(); - console.log(`Message received: ${message}`); - - // MongoDB logic for handling received message - try { - interface Subscription extends Document { - id: string; - message: string; - } - - const subscriptionSchema = new Schema({ - id: String, - message: String, - }); - - const SubscriptionModel = mongoose.model('Subscription', subscriptionSchema); - const subscription = { - id: uuidv1(), - message: message, - }; - - await SubscriptionModel.create(subscription); - } catch (error) { - - // Simulate a 404 error - if (!message) { - throw { status: 404, message: 'Not Found' }; - } +const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); - // Simulate a 403 error - if (message === 'Forbidden') { - throw { status: 403, message: 'Forbidden' }; +client.on('connect', () => { + console.log("Broker connected"); + client.subscribe(topic, (err) => { + if (err) { + console.error(`Error subscribing to topic: ${err}`); + } else { + console.log(`Subscribed to topic: ${topic}`); } + }); +}); - // Simulate a 401 error - if (message === 'Unauthorized') { - throw { status: 401, message: 'Unauthorized' }; - } - - console.error(error); - } +client.on('message', (topic, message) => { + console.log(`Received message from topic ${topic}: ${message.toString()}`); + // Process the received message as needed }); -// Define a route to check subscription status (example) -router.get('/status', (req: any, res: any) => { - res.status(200).json({ message: 'Subscriber is running' }); +client.on('error', (error) => { + console.error(error); }); -export default router; \ No newline at end of file +const subscribeRouter = express.Router(); + +// Define subscription routes if needed +// Example: +// subscribeRouter.get('/subscribe', (req, res) => { +// res.send('Subscribe endpoint'); +// }); + +export { subscribeRouter }; \ No newline at end of file diff --git a/src/routers/publishRoutes.ts b/src/routers/publishRoutes.ts new file mode 100644 index 00000000..366905be --- /dev/null +++ b/src/routers/publishRoutes.ts @@ -0,0 +1,18 @@ +import express from 'express'; +import { + registerAccount, + getAllAccounts, + getAccountById, + deleteAccountById, + publishMessage, +} from '../controllers/publishController'; + +const router = express.Router(); + +router.post('/accounts/new', registerAccount); +router.get('/accounts/all', getAllAccounts); +router.get('/accounts/:id', getAccountById); +router.delete('/accounts/:id/delete', deleteAccountById); +router.get('/:id', publishMessage); + +export default router; diff --git a/src/routers/subscribeRoutes.ts b/src/routers/subscribeRoutes.ts new file mode 100644 index 00000000..d2bfd3c1 --- /dev/null +++ b/src/routers/subscribeRoutes.ts @@ -0,0 +1,8 @@ +import express from 'express'; +import { checkSubscriptionStatus } from '../controllers/subscribeController'; + +const router = express.Router(); + +router.get('/status', checkSubscriptionStatus); + +export default router; diff --git a/src/routers/userRoutes.ts b/src/routers/userRoutes.ts new file mode 100644 index 00000000..00d6971e --- /dev/null +++ b/src/routers/userRoutes.ts @@ -0,0 +1,12 @@ +import express from 'express'; +import * as userController from '../controllers/userController'; + +const router = express.Router(); + +// Define routes +router.post('/users/register', userController.registerUser); +router.get('/users/all', userController.getAllUsers); +router.get('/users/:id', userController.getUserById); +router.delete('/users/:id/delete', userController.deleteUserById); + +export default router; diff --git a/src/routes/routes.ts b/src/routes/routes.ts index c74f4eed..83f75884 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,7 +1,7 @@ import express from 'express'; const User = require('../models/UserSchema'); -import publishRouter from '../notification/publish/publish'; -import subscribeRouter from '../notification/subscribe/subscribe'; +import { publishRouter } from '../notification/publish/publish'; +import { subscribeRouter } from '../notification/subscribe/subscribe'; const router = express.Router(); diff --git a/src/server/server.ts b/src/server/server.ts index ad117b25..d70c550d 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -1,17 +1,41 @@ -const express = require('express') -const app = express() -const { MongoClient, ServerApiVersion } = require('mongodb'); -const mongoose = require('mongoose') -const routeURLs = require('../src/routes/routes') -const cors = require('cors') -const User = require("../models/UserSchema") +const express = require('express'); +const mongoose = require('mongoose'); +const dotenv = require('dotenv'); +const cors = require('cors'); +const publishRouter = require('../src/publish/publishRoutes'); +const subscribeRouter = require('../src/subscribe/subscribeRoutes'); +const routeURLs = require('../src/routes/routes'); + +dotenv.config(); + +const app = express(); +const port = process.env.PORT || 4000; + +// MongoDB connection const USR = process.env.MONGO_INITDB_ROOT_USERNAME; const PSW = process.env.MONGO_INITDB_ROOT_PASSWORD; const DB = process.env.MONGO_INITDB_DATABASE; -mongoose.connect(`mongodb+srv://${USR}:${PSW}@${DB}.cgornhw.mongodb.net/Luminosity`, () => console.log('Database is connected')); -app.use(express.json()) -app.use(cors()) -app.use('/app', routeURLs) -app.listen(4000, () => console.log("server is up and running")) \ No newline at end of file +mongoose.connect(`mongodb+srv://${USR}:${PSW}@${DB}.cgornhw.mongodb.net/Luminosity`, { + useNewUrlParser: true, + useUnifiedTopology: true, +}, () => { + console.log('Database is connected'); +}).catch((error: any) => { + console.error('Database connection error:', error); +}); + +// Middleware setup +app.use(express.json()); +app.use(cors()); + +// Route setup +app.use('/app', routeURLs); // Existing routes +app.use('/publish', publishRouter); // Publish service routes +app.use('/subscribe', subscribeRouter); // Subscribe service routes + +// Start the server +app.listen(port, () => { + console.log(`Server is up and running on port ${port}`); +}); diff --git a/yarn.lock b/yarn.lock index 274a118f..7b02aeca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1109,10 +1109,10 @@ resolved "https://registry.npmjs.org/@babel/regjsgen/-/regjsgen-0.8.0.tgz" integrity sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA== -"@babel/runtime@^7.1.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.16.3", "@babel/runtime@^7.23.2", "@babel/runtime@^7.8.4": - version "7.23.2" - resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.2.tgz" - integrity sha512-mM8eg4yl5D6i3lu2QKPuPH4FArvJ8KhTofbE7jwMUv9KX5mBvwPAqnV3MlyBNqdp9RyRKP6Yck8TrfYrPvX3bg== +"@babel/runtime@^7.1.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.16.3", "@babel/runtime@^7.23.2", "@babel/runtime@^7.23.8", "@babel/runtime@^7.24.5", "@babel/runtime@^7.8.4": + version "7.24.7" + resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.7.tgz" + integrity sha512-UwgBRMjJP+xv857DCngvqXI3Iq6J4v0wXmwc6sapg+zyhbwmQX67LUEFrkK5tbyJ30jGuG3ZvWpBiB9LCy1kWw== dependencies: regenerator-runtime "^0.14.0" @@ -2295,6 +2295,13 @@ dependencies: mongoose "*" +"@types/mqtt@^2.5.0": + version "2.5.0" + resolved "https://registry.npmjs.org/@types/mqtt/-/mqtt-2.5.0.tgz" + integrity sha512-n+0/ErBin30j+UbhcHGK/STjHjh65k85WNR6NlUjRG0g9yctpF12pS+SOkwz0wmp+7momAo9Cyi4Wmvy8UsCQg== + dependencies: + mqtt "*" + "@types/node-forge@^1.3.0": version "1.3.10" resolved "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.10.tgz" @@ -2334,6 +2341,14 @@ resolved "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz" integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ== +"@types/readable-stream@^4.0.0", "@types/readable-stream@^4.0.5": + version "4.0.14" + resolved "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.14.tgz" + integrity sha512-xZn/AuUbCMShGsqH/ehZtGDwQtbx00M9rZ2ENLe4tOjFZ/JFeWMhEZkk2fEe1jAUqqEAURIkFJ7Az/go8mM1/w== + dependencies: + "@types/node" "*" + safe-buffer "~5.1.1" + "@types/resolve@1.17.1": version "1.17.1" resolved "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz" @@ -2392,6 +2407,11 @@ resolved "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz" integrity sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw== +"@types/uuid@^10.0.0": + version "10.0.0" + resolved "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz" + integrity sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ== + "@types/webidl-conversions@*": version "7.0.3" resolved "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz" @@ -2404,7 +2424,7 @@ dependencies: "@types/webidl-conversions" "*" -"@types/ws@^8.5.5": +"@types/ws@^8.5.5", "@types/ws@^8.5.9": version "8.5.10" resolved "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz" integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A== @@ -2662,6 +2682,13 @@ abab@^2.0.3, abab@^2.0.5: resolved "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz" integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA== +abort-controller@^3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz" + integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== + dependencies: + event-target-shim "^5.0.0" + accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.8: version "1.3.8" resolved "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz" @@ -3203,6 +3230,11 @@ balanced-match@^1.0.0: resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +base64-js@^1.3.1: + version "1.5.1" + resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz" + integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== + batch@0.6.1: version "0.6.1" resolved "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz" @@ -3229,6 +3261,16 @@ binary-extensions@^2.0.0: resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== +bl@^6.0.8: + version "6.0.13" + resolved "https://registry.npmjs.org/bl/-/bl-6.0.13.tgz" + integrity sha512-tMncAcpsyjZgAVbVFupVIaB2xud13xxT59fdHkuszY2jdZkqIWfpQdmII1fOe3kOGAz0mNLTIHEm+KxpYsQKKg== + dependencies: + "@types/readable-stream" "^4.0.0" + buffer "^6.0.3" + inherits "^2.0.4" + readable-stream "^4.2.0" + bluebird@^3.7.2: version "3.7.2" resolved "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz" @@ -3321,6 +3363,14 @@ buffer-from@^1.0.0: resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== +buffer@^6.0.3: + version "6.0.3" + resolved "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz" + integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.2.1" + builtin-modules@^3.1.0: version "3.3.0" resolved "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz" @@ -3588,6 +3638,11 @@ commander@^8.3.0: resolved "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz" integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww== +commist@^3.2.0: + version "3.2.0" + resolved "https://registry.npmjs.org/commist/-/commist-3.2.0.tgz" + integrity sha512-4PIMoPniho+LqXmpS5d3NuGYncG6XWlkBSVGiWycL22dd42OYdUGil2CWuzklaJoNxyxUSpO4MKIBU94viWNAw== + common-path-prefix@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/common-path-prefix/-/common-path-prefix-3.0.0.tgz" @@ -3628,6 +3683,16 @@ concat-map@0.0.1: resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz" integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== +concat-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz" + integrity sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A== + dependencies: + buffer-from "^1.0.0" + inherits "^2.0.3" + readable-stream "^3.0.2" + typedarray "^0.0.6" + confusing-browser-globals@^1.0.11: version "1.0.11" resolved "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz" @@ -3972,7 +4037,7 @@ debug@^3.2.7: dependencies: ms "^2.1.1" -debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4, debug@4, debug@4.x: +debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@4, debug@4.x: version "4.3.4" resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -4756,12 +4821,17 @@ etag@~1.8.1: resolved "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz" integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg== +event-target-shim@^5.0.0: + version "5.0.1" + resolved "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz" + integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== + eventemitter3@^4.0.0: version "4.0.7" resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz" integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== -events@^3.2.0: +events@^3.2.0, events@^3.3.0: version "3.3.0" resolved "https://registry.npmjs.org/events/-/events-3.3.0.tgz" integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q== @@ -4875,6 +4945,14 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: resolved "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz" integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw== +fast-unique-numbers@^8.0.13: + version "8.0.13" + resolved "https://registry.npmjs.org/fast-unique-numbers/-/fast-unique-numbers-8.0.13.tgz" + integrity sha512-7OnTFAVPefgw2eBJ1xj2PGGR9FwYzSUso9decayHgCDX4sJkHLdcsYTytTg+tYv+wKF3U8gJuSBz2jJpQV4u/g== + dependencies: + "@babel/runtime" "^7.23.8" + tslib "^2.6.2" + fastq@^1.6.0: version "1.15.0" resolved "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz" @@ -5338,6 +5416,11 @@ he@^1.2.0: resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +help-me@^5.0.0: + version "5.0.0" + resolved "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz" + integrity sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg== + hoopy@^0.1.4: version "0.1.4" resolved "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz" @@ -5508,6 +5591,11 @@ identity-obj-proxy@^3.0.0: dependencies: harmony-reflect "^1.4.6" +ieee754@^1.2.1: + version "1.2.1" + resolved "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz" + integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== + ignore@^5.2.0: version "5.3.0" resolved "https://registry.npmjs.org/ignore/-/ignore-5.3.0.tgz" @@ -5547,7 +5635,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.3, inherits@2, inherits@2.0.4: +inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3, inherits@2, inherits@2.0.4: version "2.0.4" resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -6785,6 +6873,11 @@ jiti@^1.19.1: resolved "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz" integrity sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q== +js-sdsl@4.3.0: + version "4.3.0" + resolved "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz" + integrity sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz" @@ -7096,6 +7189,11 @@ lower-case@^2.0.2: dependencies: tslib "^2.0.3" +lru-cache@^10.0.1: + version "10.2.2" + resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz" + integrity sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ== + lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz" @@ -7260,7 +7358,7 @@ minimatch@^5.0.1: dependencies: brace-expansion "^2.0.1" -minimist@^1.2.0, minimist@^1.2.6: +minimist@^1.2.0, minimist@^1.2.6, minimist@^1.2.8: version "1.2.8" resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz" integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== @@ -7307,6 +7405,38 @@ mpath@0.9.0: resolved "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz" integrity sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew== +mqtt-packet@^9.0.0: + version "9.0.0" + resolved "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-9.0.0.tgz" + integrity sha512-8v+HkX+fwbodsWAZIZTI074XIoxVBOmPeggQuDFCGg1SqNcC+uoRMWu7J6QlJPqIUIJXmjNYYHxBBLr1Y/Df4w== + dependencies: + bl "^6.0.8" + debug "^4.3.4" + process-nextick-args "^2.0.1" + +mqtt@*, mqtt@^5.2.0: + version "5.7.2" + resolved "https://registry.npmjs.org/mqtt/-/mqtt-5.7.2.tgz" + integrity sha512-b5xIA9J/K1LTubSWKaNYYLxYIusQdip6o9/8bRWad2TelRr8xLifjQt+SnamDAwMp3O6NdvR9E8ae7VMuN02kg== + dependencies: + "@types/readable-stream" "^4.0.5" + "@types/ws" "^8.5.9" + commist "^3.2.0" + concat-stream "^2.0.0" + debug "^4.3.4" + help-me "^5.0.0" + lru-cache "^10.0.1" + minimist "^1.2.8" + mqtt "^5.2.0" + mqtt-packet "^9.0.0" + number-allocator "^1.0.14" + readable-stream "^4.4.2" + reinterval "^1.1.0" + rfdc "^1.3.0" + split2 "^4.2.0" + worker-timers "^7.1.4" + ws "^8.17.1" + mquery@5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz" @@ -7447,6 +7577,14 @@ nth-check@^2.0.1: dependencies: boolbase "^1.0.0" +number-allocator@^1.0.14: + version "1.0.14" + resolved "https://registry.npmjs.org/number-allocator/-/number-allocator-1.0.14.tgz" + integrity sha512-OrL44UTVAvkKdOdRQZIJpLkAdjXGTRda052sN4sO77bKEzYYqWKMBjQvrJFzqygI99gL6Z4u2xctPW1tB8ErvA== + dependencies: + debug "^4.3.1" + js-sdsl "4.3.0" + nwsapi@^2.2.0: version "2.2.7" resolved "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz" @@ -8395,11 +8533,16 @@ pretty-format@^29.0.0, pretty-format@^29.7.0: ansi-styles "^5.0.0" react-is "^18.0.0" -process-nextick-args@~2.0.0: +process-nextick-args@^2.0.1, process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== +process@^0.11.10: + version "0.11.10" + resolved "https://registry.npmjs.org/process/-/process-0.11.10.tgz" + integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A== + promise@^8.1.0: version "8.3.0" resolved "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz" @@ -8672,7 +8815,7 @@ readable-stream@^2.0.1: string_decoder "~1.1.1" util-deprecate "~1.0.1" -readable-stream@^3.0.6: +readable-stream@^3.0.2, readable-stream@^3.0.6: version "3.6.2" resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz" integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA== @@ -8681,6 +8824,28 @@ readable-stream@^3.0.6: string_decoder "^1.1.1" util-deprecate "^1.0.1" +readable-stream@^4.2.0: + version "4.5.2" + resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz" + integrity sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g== + dependencies: + abort-controller "^3.0.0" + buffer "^6.0.3" + events "^3.3.0" + process "^0.11.10" + string_decoder "^1.3.0" + +readable-stream@^4.4.2: + version "4.5.2" + resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz" + integrity sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g== + dependencies: + abort-controller "^3.0.0" + buffer "^6.0.3" + events "^3.3.0" + process "^0.11.10" + string_decoder "^1.3.0" + readdirp@~3.6.0: version "3.6.0" resolved "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz" @@ -8769,6 +8934,11 @@ regjsparser@^0.9.1: dependencies: jsesc "~0.5.0" +reinterval@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/reinterval/-/reinterval-1.1.0.tgz" + integrity sha512-QIRet3SYrGp0HUHO88jVskiG6seqUGC5iAG7AwI/BV4ypGcuqk9Du6YQBUOUqm9c8pw1eyLoIaONifRua1lsEQ== + relateurl@^0.2.7: version "0.2.7" resolved "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz" @@ -8866,6 +9036,11 @@ reusify@^1.0.4: resolved "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== +rfdc@^1.3.0: + version "1.4.1" + resolved "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz" + integrity sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA== + rimraf@^3.0.0, rimraf@^3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz" @@ -9318,6 +9493,11 @@ spdy@^4.0.2: select-hose "^2.0.0" spdy-transport "^3.0.0" +split2@^4.2.0: + version "4.2.0" + resolved "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz" + integrity sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg== + sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz" @@ -9357,7 +9537,7 @@ statuses@2.0.1: resolved "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz" integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ== -string_decoder@^1.1.1: +string_decoder@^1.1.1, string_decoder@^1.3.0: version "1.3.0" resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz" integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== @@ -9810,7 +9990,7 @@ tslib@^1.8.1: resolved "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.0.3, "tslib@1 || 2": +tslib@^2.0.3, tslib@^2.6.2, "tslib@1 || 2": version "2.6.2" resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz" integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q== @@ -9926,6 +10106,11 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typedarray@^0.0.6: + version "0.0.6" + resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz" + integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA== + typescript-coverage-report@^0.7.0: version "0.7.0" resolved "https://registry.npmjs.org/typescript-coverage-report/-/typescript-coverage-report-0.7.0.tgz" @@ -10566,6 +10751,34 @@ workbox-window@6.6.0: "@types/trusted-types" "^2.0.2" workbox-core "6.6.0" +worker-timers-broker@^6.1.8: + version "6.1.8" + resolved "https://registry.npmjs.org/worker-timers-broker/-/worker-timers-broker-6.1.8.tgz" + integrity sha512-FUCJu9jlK3A8WqLTKXM9E6kAmI/dR1vAJ8dHYLMisLNB/n3GuaFIjJ7pn16ZcD1zCOf7P6H62lWIEBi+yz/zQQ== + dependencies: + "@babel/runtime" "^7.24.5" + fast-unique-numbers "^8.0.13" + tslib "^2.6.2" + worker-timers-worker "^7.0.71" + +worker-timers-worker@^7.0.71: + version "7.0.71" + resolved "https://registry.npmjs.org/worker-timers-worker/-/worker-timers-worker-7.0.71.tgz" + integrity sha512-ks/5YKwZsto1c2vmljroppOKCivB/ma97g9y77MAAz2TBBjPPgpoOiS1qYQKIgvGTr2QYPT3XhJWIB6Rj2MVPQ== + dependencies: + "@babel/runtime" "^7.24.5" + tslib "^2.6.2" + +worker-timers@^7.1.4: + version "7.1.8" + resolved "https://registry.npmjs.org/worker-timers/-/worker-timers-7.1.8.tgz" + integrity sha512-R54psRKYVLuzff7c1OTFcq/4Hue5Vlz4bFtNEIarpSiCYhpifHU3aIQI29S84o1j87ePCYqbmEJPqwBTf+3sfw== + dependencies: + "@babel/runtime" "^7.24.5" + tslib "^2.6.2" + worker-timers-broker "^6.1.8" + worker-timers-worker "^7.0.71" + wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" @@ -10603,10 +10816,10 @@ ws@^7.4.6: resolved "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz" integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== -ws@^8.13.0: - version "8.14.2" - resolved "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz" - integrity sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g== +ws@^8.13.0, ws@^8.17.1: + version "8.17.1" + resolved "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz" + integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ== xml-name-validator@^3.0.0: version "3.0.0" From 590fbc7a3fd204d28b18621c5f00168562266f09 Mon Sep 17 00:00:00 2001 From: Aaron Levitt <108915844+pogi7@users.noreply.github.com> Date: Sat, 22 Jun 2024 06:59:44 +0000 Subject: [PATCH 06/14] moved docker compose to root of server repo and integrate with controllers & routes Signed-off-by: Aaron Levitt <108915844+pogi7@users.noreply.github.com> --- Dockerfile | 6 + docker-compose.yaml | 104 ++++-- package-lock.json | 335 ++++++++++++------ package.json | 14 +- src/controllers/accountController.ts | 87 +++++ src/controllers/publishController.ts | 109 +----- src/controllers/subscribeController.ts | 6 +- .../accountRoutes.ts} | 4 +- src/routes/publishRoutes.ts | 10 + src/{routers => routes}/subscribeRoutes.ts | 0 src/{routers => routes}/userRoutes.ts | 0 src/server/Dockerfile | 0 src/server/server.ts | 78 ++-- yarn.lock | 133 ++++--- 14 files changed, 578 insertions(+), 308 deletions(-) create mode 100644 Dockerfile create mode 100644 src/controllers/accountController.ts rename src/{routers/publishRoutes.ts => routes/accountRoutes.ts} (79%) create mode 100644 src/routes/publishRoutes.ts rename src/{routers => routes}/subscribeRoutes.ts (100%) rename src/{routers => routes}/userRoutes.ts (100%) delete mode 100644 src/server/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..dd7d2828 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM node:latest +WORKDIR /app +COPY ["package.json", "package-lock.json*", "tsconfig.json*", "/app/"] +COPY ["src", "/app/src"] +RUN ["/bin/bash", "-c", "npm install"] +EXPOSE 4000 \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 74428558..ea5c5f6a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,34 +1,80 @@ -version: "3.8" - +version: "3" services: - # account: - # build: "src/account/" - # command: "npm run account" - # ports: - # - "5000:5000" - # env_file: "src/account/.env" - # dns: - # - "8.8.8.8" - models: - build: "src/models/" - command: "echo Models Container Working" - routes: - build: "src/routes/" - command: "npx ts-node github.ts" + activemq: + image: rmohr/activemq + container_name: activemq + networks: + - backend + ports: + - "8161:8161" + - "1883:1883" + env_file: ".env" + + # server: + # build: "." + # command: "npm run server" + # ports: + # - "4000:4000" + # networks: + # - backend + # env_file: ".env" + # depends_on: + # - "activemq" + account: + container_name: "account" + build: "src/account/" + command: "npm run account" + ports: + - "5000:5000" + env_file: ".env" + dns: + - "8.8.8.8" + networks: + - backend + publish: + container_name: "publish" + build: + context: 'src/notification/publish' + env_file: ".env" ports: - - "4000:4000" - - "8080:8080" - env_file: "src/routes/.env" + - 4000:4000 + networks: + - backend depends_on: - - "models" - client: - build: "client/" - command: "npm start" - ports: - - "3000:3000" - env_file: "src/routes/.env" -# Requires server services to run before running client servers + - activemq + + subscribe: + container_name: subscribe + build: + context: 'src/notification/subscribe' + env_file: ".env" + networks: + - backend depends_on: - # - "account" - - "routes" + - activemq +# models: +# build: "src/models/" +# command: "echo Models Container Working" +# routes: +# build: "src/routes/" +# command: "npx ts-node github.ts" +# ports: +# - "4000:4000" +# - "8080:8080" +# env_file: "src/routes/.env" +# depends_on: +# - "models" +# client: +# build: "client/" +# command: "npm start" +# ports: +# - "3000:3000" +# env_file: "src/routes/.env" +# # Requires server services to run before running client servers +# depends_on: +# # - "account" +# - "routes" + +networks: + backend: diff --git a/package-lock.json b/package-lock.json index f6b00343..76aedc18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,14 +11,19 @@ "dependencies": { "@types/mqtt": "^2.5.0", "@types/uuid": "^10.0.0", + "cors": "^2.8.5", "dotenv": "^16.4.1", "express": "^4.18.2", "jest": "^29.7.0", + "mongodb": "^6.7.0", "mongoose": "^8.1.1", + "mqtt": "^5.7.2", "react-scripts": "^5.0.1", - "typescript-coverage-report": "^0.7.0" + "typescript-coverage-report": "^0.7.0", + "uuid": "^10.0.0" }, "devDependencies": { + "@types/cors": "^2.8.17", "@types/dotenv": "^8.2.0", "@types/jest": "^29.5.6", "@types/mongoose": "^5.11.97", @@ -2858,9 +2863,9 @@ "integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==" }, "node_modules/@mongodb-js/saslprep": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.4.tgz", - "integrity": "sha512-8zJ8N1x51xo9hwPh6AWnKdLGEC5N3lDa6kms1YHmFBoRhTpJR6HG8wWk0td1MVCu9cD4YBrvjZEtd5Obw0Fbnw==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.7.tgz", + "integrity": "sha512-dCHW/oEX0KJ4NjDULBo3JiOaK5+6axtpBbS+ao2ZInoAL9/YRQLhXzSNAFz7hP4nzLkIqsfYAK/PDE3+XHny0Q==", "dependencies": { "sparse-bitfield": "^3.0.3" } @@ -3509,6 +3514,15 @@ "@types/node": "*" } }, + "node_modules/@types/cors": { + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/dotenv": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/@types/dotenv/-/dotenv-8.2.0.tgz", @@ -5096,12 +5110,12 @@ "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" }, "node_modules/body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", "dependencies": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "content-type": "~1.0.5", "debug": "2.6.9", "depd": "2.0.0", "destroy": "1.2.0", @@ -5109,7 +5123,7 @@ "iconv-lite": "0.4.24", "on-finished": "2.4.1", "qs": "6.11.0", - "raw-body": "2.5.1", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -5176,11 +5190,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -5231,9 +5245,9 @@ } }, "node_modules/bson": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz", - "integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.7.0.tgz", + "integrity": "sha512-w2IquM5mYzYZv6rs3uN2DZTOBe2a0zXLj53TGDqwF4l6Sz/XsISrisXOJihArF9+BZ6Cq/GjVht7Sjfmri7ytQ==", "engines": { "node": ">=16.20.1" } @@ -5758,9 +5772,9 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==" }, "node_modules/cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", "engines": { "node": ">= 0.6" } @@ -5807,6 +5821,18 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/cosmiconfig": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz", @@ -6676,9 +6702,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/ejs": { - "version": "3.1.9", - "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", - "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", "dependencies": { "jake": "^10.8.5" }, @@ -7678,16 +7704,16 @@ } }, "node_modules/express": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", - "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", + "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.20.1", + "body-parser": "1.20.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.5.0", + "cookie": "0.6.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -7882,9 +7908,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -7983,9 +8009,9 @@ "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==" }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", @@ -10898,9 +10924,9 @@ } }, "node_modules/jsdom/node_modules/ws": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", - "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", "engines": { "node": ">=8.3.0" }, @@ -11486,12 +11512,12 @@ } }, "node_modules/mongodb": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz", - "integrity": "sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz", + "integrity": "sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==", "dependencies": { - "@mongodb-js/saslprep": "^1.1.0", - "bson": "^6.2.0", + "@mongodb-js/saslprep": "^1.1.5", + "bson": "^6.7.0", "mongodb-connection-string-url": "^3.0.0" }, "engines": { @@ -11591,6 +11617,51 @@ "url": "https://opencollective.com/mongoose" } }, + "node_modules/mongoose/node_modules/mongodb": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz", + "integrity": "sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA==", + "dependencies": { + "@mongodb-js/saslprep": "^1.1.0", + "bson": "^6.2.0", + "mongodb-connection-string-url": "^3.0.0" + }, + "engines": { + "node": ">=16.20.1" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.188.0", + "@mongodb-js/zstd": "^1.1.0", + "gcp-metadata": "^5.2.0", + "kerberos": "^2.0.1", + "mongodb-client-encryption": ">=6.0.0 <7", + "snappy": "^7.2.2", + "socks": "^2.7.1" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, "node_modules/mongoose/node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -11821,6 +11892,16 @@ "node": ">=10" } }, + "node_modules/node-notifier/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "optional": true, + "peer": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/node-notifier/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -13844,9 +13925,9 @@ } }, "node_modules/raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", @@ -16259,6 +16340,14 @@ "websocket-driver": "^0.7.4" } }, + "node_modules/sockjs/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/source-list-map": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz", @@ -17630,9 +17719,13 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } @@ -17776,9 +17869,9 @@ } }, "node_modules/webpack-dev-middleware": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz", - "integrity": "sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA==", + "version": "5.3.4", + "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.4.tgz", + "integrity": "sha512-BVdTqhhs+0IfoeAf7EoH5WE+exCmqGerHfDM0IL096Px60Tq2Mn9MAbnaGUe6HiMa41KMCYF19gyzZmBcq/o4Q==", "dependencies": { "colorette": "^2.0.10", "memfs": "^3.4.3", @@ -20498,9 +20591,9 @@ "integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==" }, "@mongodb-js/saslprep": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.4.tgz", - "integrity": "sha512-8zJ8N1x51xo9hwPh6AWnKdLGEC5N3lDa6kms1YHmFBoRhTpJR6HG8wWk0td1MVCu9cD4YBrvjZEtd5Obw0Fbnw==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.7.tgz", + "integrity": "sha512-dCHW/oEX0KJ4NjDULBo3JiOaK5+6axtpBbS+ao2ZInoAL9/YRQLhXzSNAFz7hP4nzLkIqsfYAK/PDE3+XHny0Q==", "requires": { "sparse-bitfield": "^3.0.3" } @@ -20938,6 +21031,15 @@ "@types/node": "*" } }, + "@types/cors": { + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/dotenv": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/@types/dotenv/-/dotenv-8.2.0.tgz", @@ -22170,12 +22272,12 @@ "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" }, "body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", "requires": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "content-type": "~1.0.5", "debug": "2.6.9", "depd": "2.0.0", "destroy": "1.2.0", @@ -22183,7 +22285,7 @@ "iconv-lite": "0.4.24", "on-finished": "2.4.1", "qs": "6.11.0", - "raw-body": "2.5.1", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -22242,11 +22344,11 @@ } }, "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "requires": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" } }, "browser-process-hrtime": { @@ -22274,9 +22376,9 @@ } }, "bson": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz", - "integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==" + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.7.0.tgz", + "integrity": "sha512-w2IquM5mYzYZv6rs3uN2DZTOBe2a0zXLj53TGDqwF4l6Sz/XsISrisXOJihArF9+BZ6Cq/GjVht7Sjfmri7ytQ==" }, "buffer": { "version": "6.0.3", @@ -22657,9 +22759,9 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==" }, "cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==" + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==" }, "cookie-signature": { "version": "1.0.6", @@ -22689,6 +22791,15 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "cosmiconfig": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz", @@ -23289,9 +23400,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "ejs": { - "version": "3.1.9", - "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", - "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", "requires": { "jake": "^10.8.5" } @@ -24019,16 +24130,16 @@ } }, "express": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", - "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", + "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", "requires": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.20.1", + "body-parser": "1.20.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.5.0", + "cookie": "0.6.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -24195,9 +24306,9 @@ "integrity": "sha512-pjmC+bkIF8XI7fWaH8KxHcZL3DPybs1roSKP4rKDvy20tAWwIObE4+JIseG2byfGKhud5ZnM4YSGKBz7Sh0ndQ==" }, "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "requires": { "to-regex-range": "^5.0.1" } @@ -24276,9 +24387,9 @@ "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==" }, "follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==" + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==" }, "for-each": { "version": "0.3.3", @@ -26392,9 +26503,9 @@ } }, "ws": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", - "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", "requires": {} } } @@ -26833,12 +26944,12 @@ } }, "mongodb": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz", - "integrity": "sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz", + "integrity": "sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==", "requires": { - "@mongodb-js/saslprep": "^1.1.0", - "bson": "^6.2.0", + "@mongodb-js/saslprep": "^1.1.5", + "bson": "^6.7.0", "mongodb-connection-string-url": "^3.0.0" } }, @@ -26889,6 +27000,16 @@ "sift": "16.0.1" }, "dependencies": { + "mongodb": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz", + "integrity": "sha512-tt0KuGjGtLUhLoU263+xvQmPHEGTw5LbcNC73EoFRYgSHwZt5tsoJC110hDyO1kjQzpgNrpdcSza9PknWN4LrA==", + "requires": { + "@mongodb-js/saslprep": "^1.1.0", + "bson": "^6.2.0", + "mongodb-connection-string-url": "^3.0.0" + } + }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -27070,6 +27191,13 @@ "lru-cache": "^6.0.0" } }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "optional": true, + "peer": true + }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -28329,9 +28457,9 @@ "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" }, "raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "requires": { "bytes": "3.1.2", "http-errors": "2.0.0", @@ -30163,6 +30291,13 @@ "faye-websocket": "^0.11.3", "uuid": "^8.3.2", "websocket-driver": "^0.7.4" + }, + "dependencies": { + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + } } }, "source-list-map": { @@ -31179,9 +31314,9 @@ "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, "uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==" }, "v8-compile-cache-lib": { "version": "3.0.1", @@ -31307,9 +31442,9 @@ } }, "webpack-dev-middleware": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz", - "integrity": "sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA==", + "version": "5.3.4", + "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.4.tgz", + "integrity": "sha512-BVdTqhhs+0IfoeAf7EoH5WE+exCmqGerHfDM0IL096Px60Tq2Mn9MAbnaGUe6HiMa41KMCYF19gyzZmBcq/o4Q==", "requires": { "colorette": "^2.0.10", "memfs": "^3.4.3", @@ -31957,4 +32092,4 @@ "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 4d4b249b..6a002c7a 100644 --- a/package.json +++ b/package.json @@ -2,30 +2,36 @@ "name": "src", "version": "1.0.0", "description": "backend", - "main": "index.ts", + "main": "server.ts", "directories": { "test": "tests" }, "scripts": { "test": "jest test", - "ts-coverage": "typescript-coverage-report" + "ts-coverage": "typescript-coverage-report", + "server": "npx ts-node src/server/server.ts" }, "author": "", "license": "ISC", "dependencies": { "@types/mqtt": "^2.5.0", "@types/uuid": "^10.0.0", + "cors": "^2.8.5", "dotenv": "^16.4.1", "express": "^4.18.2", "jest": "^29.7.0", + "mongodb": "^6.7.0", "mongoose": "^8.1.1", + "mqtt": "^5.7.2", "react-scripts": "^5.0.1", - "typescript-coverage-report": "^0.7.0" + "typescript-coverage-report": "^0.7.0", + "uuid": "^10.0.0" }, "devDependencies": { + "@types/cors": "^2.8.17", "@types/dotenv": "^8.2.0", "@types/jest": "^29.5.6", "@types/mongoose": "^5.11.97", "@types/node": "^20.10.0" } -} \ No newline at end of file +} diff --git a/src/controllers/accountController.ts b/src/controllers/accountController.ts new file mode 100644 index 00000000..90b3ee49 --- /dev/null +++ b/src/controllers/accountController.ts @@ -0,0 +1,87 @@ +import { Request, Response } from 'express'; +import Device from '../models/DeviceSchema'; // Import Device model +import User from '../models/UserSchema'; // Import User model + +// Register account +export const registerAccount = async (req: Request, res: Response) => { + try { + const { email, name, deletionDate, devicesLinked } = req.body; + const currentDate = new Date(); // Set current timestamp + const newAccountData = { + email, + name, + creationDate: currentDate, + lastUpdated: currentDate, + deletionDate: deletionDate ? new Date(deletionDate) : null, + }; + + const newAccount = new User(newAccountData); + + // Handle devicesLinked + if (devicesLinked && devicesLinked.length > 0) { + const devices = await Device.insertMany(devicesLinked); // Use Device to refer to the Device model + newAccount.devicesLinked = devices.map((device: any) => device._id); // Use explicit typing or adjust as needed + } else { + newAccount.devicesLinked = []; + } + + const savedAccount = await newAccount.save(); // Save the new account to the database + res.status(201).json(savedAccount); // HTTP 201 Created status code for successful creation + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } + }; + + // Get all accounts + export const getAllAccounts = async (_req: Request, res: Response) => { + try { + const events = await User.find(); // Use User model + res.json(events); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } + }; + + // Get account by ID + export const getAccountById = async (req: Request, res: Response) => { + try { + const event = await User.findById(req.params.id); // Use User model + + if (!event) { + res.status(404).json({ error: 'Event not found' }); + return; + } + + if (!req.params.id) { + res.status(400).json({ error: 'Bad Request' }); + return; + } + + res.json(event); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } + }; + + // Delete account by ID + export const deleteAccountById = async (req: Request, res: Response) => { + try { + const events = await User.findByIdAndDelete(req.params.id); // Use User model + + if (!events) { + // If the document doesn't exist, return a 404 Not Found response + res.status(404).json({ error: 'Event not found' }); + return; + } + + // If the document is successfully deleted, return a success message + res.json({ message: 'Event deleted successfully' }); + } catch (error) { + // If an error occurs during deletion, return a 500 Internal Server Error response + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } + }; \ No newline at end of file diff --git a/src/controllers/publishController.ts b/src/controllers/publishController.ts index 96f4abf7..bf5901d6 100644 --- a/src/controllers/publishController.ts +++ b/src/controllers/publishController.ts @@ -5,8 +5,7 @@ import mongoose from 'mongoose'; import dotenv from 'dotenv'; dotenv.config(); import db from '../notification/publish/db'; // Import the db.ts file to access the dbURI variable -import Device from '../models/DeviceSchema'; // Import Device model -import User from '../models/UserSchema'; // Import User model + const options = { username: process.env.ACTIVE_MQ_USERNAME, @@ -17,98 +16,20 @@ const options = { const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion // Establish Mongoose connection -mongoose.connect(db.dbURI, { - useNewUrlParser: true, - useUnifiedTopology: true, -} as mongoose.ConnectOptions).then(() => { - console.log('MongoDB connected'); -}).catch((error) => { - console.error('MongoDB connection error:', error); -}); - -// Register account -export const registerAccount = async (req: Request, res: Response) => { - try { - const { email, name, deletionDate, devicesLinked } = req.body; - const currentDate = new Date(); // Set current timestamp - const newAccountData = { - email, - name, - creationDate: currentDate, - lastUpdated: currentDate, - deletionDate: deletionDate ? new Date(deletionDate) : null, - }; - - const newAccount = new User(newAccountData); - - // Handle devicesLinked - if (devicesLinked && devicesLinked.length > 0) { - const devices = await Device.insertMany(devicesLinked); // Use Device to refer to the Device model - newAccount.devicesLinked = devices.map((device: any) => device._id); // Use explicit typing or adjust as needed - } else { - newAccount.devicesLinked = []; - } - - const savedAccount = await newAccount.save(); // Save the new account to the database - res.status(201).json(savedAccount); // HTTP 201 Created status code for successful creation - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } -}; - -// Get all accounts -export const getAllAccounts = async (_req: Request, res: Response) => { - try { - const events = await User.find(); // Use User model - res.json(events); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } -}; - -// Get account by ID -export const getAccountById = async (req: Request, res: Response) => { - try { - const event = await User.findById(req.params.id); // Use User model - - if (!event) { - res.status(404).json({ error: 'Event not found' }); - return; - } - - if (!req.params.id) { - res.status(400).json({ error: 'Bad Request' }); - return; - } - - res.json(event); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } -}; - -// Delete account by ID -export const deleteAccountById = async (req: Request, res: Response) => { - try { - const events = await User.findByIdAndDelete(req.params.id); // Use User model - - if (!events) { - // If the document doesn't exist, return a 404 Not Found response - res.status(404).json({ error: 'Event not found' }); - return; - } - - // If the document is successfully deleted, return a success message - res.json({ message: 'Event deleted successfully' }); - } catch (error) { - // If an error occurs during deletion, return a 500 Internal Server Error response - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } -}; +// MongoDB URL +const URL = process.env.MONGO_DB_URL; + +// Verify that URL is defined +if (URL) { + const mongo_connect = mongoose.createConnection(URL); + mongo_connect.on(`error`, console.error.bind(console, `connection error:`)); + mongo_connect.once(`open`, () => { + // Successful connection! + console.log("MongoDB database connection established successfully"); + }); +} else { + console.error("MongoDB URL is not defined in .env file."); +} // Publish message to MQTT export const publishMessage = async (req: Request, res: Response) => { diff --git a/src/controllers/subscribeController.ts b/src/controllers/subscribeController.ts index 9ebb51b5..eb3b2da1 100644 --- a/src/controllers/subscribeController.ts +++ b/src/controllers/subscribeController.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; import mqtt, { MqttClient } from 'mqtt'; -import { v1 as uuidv1 } from 'uuid'; +import { v4 as uuidv4 } from 'uuid'; import mongoose, { Schema, Document } from 'mongoose'; import dotenv from 'dotenv'; dotenv.config(); @@ -8,7 +8,7 @@ dotenv.config(); const options = { username: process.env.ACTIVE_MQ_USERNAME, password: process.env.ACTIVE_MQ_PASSWORD, - clientId: `subscribe_${uuidv1()}`, + clientId: `subscribe_${uuidv4()}`, port: 1883, }; @@ -41,7 +41,7 @@ client.on('message', async (receivedTopic, msg) => { const SubscriptionModel = mongoose.model('Subscription', subscriptionSchema); const subscription = { - id: uuidv1(), + id: uuidv4(), message: message, }; diff --git a/src/routers/publishRoutes.ts b/src/routes/accountRoutes.ts similarity index 79% rename from src/routers/publishRoutes.ts rename to src/routes/accountRoutes.ts index 366905be..43f44afc 100644 --- a/src/routers/publishRoutes.ts +++ b/src/routes/accountRoutes.ts @@ -4,8 +4,7 @@ import { getAllAccounts, getAccountById, deleteAccountById, - publishMessage, -} from '../controllers/publishController'; +} from '../controllers/accountController'; const router = express.Router(); @@ -13,6 +12,5 @@ router.post('/accounts/new', registerAccount); router.get('/accounts/all', getAllAccounts); router.get('/accounts/:id', getAccountById); router.delete('/accounts/:id/delete', deleteAccountById); -router.get('/:id', publishMessage); export default router; diff --git a/src/routes/publishRoutes.ts b/src/routes/publishRoutes.ts new file mode 100644 index 00000000..f14bb0f8 --- /dev/null +++ b/src/routes/publishRoutes.ts @@ -0,0 +1,10 @@ +import express from 'express'; +import { + publishMessage, +} from '../controllers/publishController'; + +const router = express.Router(); + +router.get('/:id', publishMessage); + +export default router; diff --git a/src/routers/subscribeRoutes.ts b/src/routes/subscribeRoutes.ts similarity index 100% rename from src/routers/subscribeRoutes.ts rename to src/routes/subscribeRoutes.ts diff --git a/src/routers/userRoutes.ts b/src/routes/userRoutes.ts similarity index 100% rename from src/routers/userRoutes.ts rename to src/routes/userRoutes.ts diff --git a/src/server/Dockerfile b/src/server/Dockerfile deleted file mode 100644 index e69de29b..00000000 diff --git a/src/server/server.ts b/src/server/server.ts index d70c550d..91f1c2aa 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -1,39 +1,71 @@ -const express = require('express'); -const mongoose = require('mongoose'); -const dotenv = require('dotenv'); -const cors = require('cors'); +import express from "express"; +import mongoose from "mongoose"; +import dotenv from "dotenv"; +import cors from "cors"; -const publishRouter = require('../src/publish/publishRoutes'); -const subscribeRouter = require('../src/subscribe/subscribeRoutes'); -const routeURLs = require('../src/routes/routes'); +import routeURLs from "../routes/routes"; +import accountRouter from "../routes/accountRoutes"; +import publishRouter from "../routes/publishRoutes"; +import subscribeRouter from "../routes/subscribeRoutes"; + +// TODO: Remove, deprecate, or archive unused commented out code +// dotenv.config(); + +// const app = express(); +// const port = process.env.PORT || 3000; + +// // Middleware +// app.use(cors()); +// app.use(express.json()); + +// // Routes +// app.use(routeURLs); +// app.use("/account", accountRouter); +// app.use("/publish", publishRouter); +// app.use("/subscribe", subscribeRouter); + +// MongoDB Connection +// const uri = process.env.MONGODB_URI as string; +// mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true }); +// const connection = mongoose.connection; +// connection.once("open", () => { +// console.log("MongoDB database connection established successfully"); +// }); + +// // Start the server +// app.listen(port, () => { +// console.log(`Server is running on port: ${port}`); +// }); dotenv.config(); const app = express(); const port = process.env.PORT || 4000; -// MongoDB connection -const USR = process.env.MONGO_INITDB_ROOT_USERNAME; -const PSW = process.env.MONGO_INITDB_ROOT_PASSWORD; -const DB = process.env.MONGO_INITDB_DATABASE; - -mongoose.connect(`mongodb+srv://${USR}:${PSW}@${DB}.cgornhw.mongodb.net/Luminosity`, { - useNewUrlParser: true, - useUnifiedTopology: true, -}, () => { - console.log('Database is connected'); -}).catch((error: any) => { - console.error('Database connection error:', error); -}); +// MongoDB URL +const URL = process.env.MONGO_DB_URL; + +// Verify that URL is defined +if (URL) { + const mongo_connect = mongoose.createConnection(URL); + mongo_connect.on(`error`, console.error.bind(console, `connection error:`)); + mongo_connect.once(`open`, () => { + // Successful connection! + console.log("MongoDB database connection established successfully"); + }); +} else { + console.error("MongoDB URL is not defined in .env file."); +} // Middleware setup app.use(express.json()); app.use(cors()); // Route setup -app.use('/app', routeURLs); // Existing routes -app.use('/publish', publishRouter); // Publish service routes -app.use('/subscribe', subscribeRouter); // Subscribe service routes +app.use("/app", routeURLs); // Existing routes +app.use("/account", accountRouter); // Account service routes +app.use("/publish", publishRouter); // Publish service routes +app.use("/subscribe", subscribeRouter); // Subscribe service routes // Start the server app.listen(port, () => { diff --git a/yarn.lock b/yarn.lock index 5003283b..ee7084e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1808,10 +1808,10 @@ resolved "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz" integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== -"@mongodb-js/saslprep@^1.1.0": - version "1.1.4" - resolved "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.4.tgz" - integrity sha512-8zJ8N1x51xo9hwPh6AWnKdLGEC5N3lDa6kms1YHmFBoRhTpJR6HG8wWk0td1MVCu9cD4YBrvjZEtd5Obw0Fbnw== +"@mongodb-js/saslprep@^1.1.0", "@mongodb-js/saslprep@^1.1.5": + version "1.1.7" + resolved "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.7.tgz" + integrity sha512-dCHW/oEX0KJ4NjDULBo3JiOaK5+6axtpBbS+ao2ZInoAL9/YRQLhXzSNAFz7hP4nzLkIqsfYAK/PDE3+XHny0Q== dependencies: sparse-bitfield "^3.0.3" @@ -2169,6 +2169,13 @@ dependencies: "@types/node" "*" +"@types/cors@^2.8.17": + version "2.8.17" + resolved "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz" + integrity sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA== + dependencies: + "@types/node" "*" + "@types/dotenv@^8.2.0": version "8.2.0" resolved "https://registry.npmjs.org/@types/dotenv/-/dotenv-8.2.0.tgz" @@ -3276,13 +3283,13 @@ bluebird@^3.7.2: resolved "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== -body-parser@1.20.1: - version "1.20.1" - resolved "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz" - integrity sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw== +body-parser@1.20.2: + version "1.20.2" + resolved "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz" + integrity sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA== dependencies: bytes "3.1.2" - content-type "~1.0.4" + content-type "~1.0.5" debug "2.6.9" depd "2.0.0" destroy "1.2.0" @@ -3290,7 +3297,7 @@ body-parser@1.20.1: iconv-lite "0.4.24" on-finished "2.4.1" qs "6.11.0" - raw-body "2.5.1" + raw-body "2.5.2" type-is "~1.6.18" unpipe "1.0.0" @@ -3325,11 +3332,11 @@ brace-expansion@^2.0.1: balanced-match "^1.0.0" braces@^3.0.2, braces@~3.0.2: - version "3.0.2" - resolved "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz" - integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + version "3.0.3" + resolved "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== dependencies: - fill-range "^7.0.1" + fill-range "^7.1.1" browser-process-hrtime@^1.0.0: version "1.0.0" @@ -3353,10 +3360,10 @@ bser@2.1.1: dependencies: node-int64 "^0.4.0" -bson@^6.2.0: - version "6.2.0" - resolved "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz" - integrity sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q== +bson@^6.2.0, bson@^6.7.0: + version "6.7.0" + resolved "https://registry.npmjs.org/bson/-/bson-6.7.0.tgz" + integrity sha512-w2IquM5mYzYZv6rs3uN2DZTOBe2a0zXLj53TGDqwF4l6Sz/XsISrisXOJihArF9+BZ6Cq/GjVht7Sjfmri7ytQ== buffer-from@^1.0.0: version "1.1.2" @@ -3710,7 +3717,7 @@ content-disposition@0.5.4: dependencies: safe-buffer "5.2.1" -content-type@~1.0.4: +content-type@~1.0.4, content-type@~1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz" integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA== @@ -3735,10 +3742,10 @@ cookie-signature@1.0.6: resolved "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz" integrity sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ== -cookie@0.5.0: - version "0.5.0" - resolved "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz" - integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== +cookie@0.6.0: + version "0.6.0" + resolved "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz" + integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== core-js-compat@^3.31.0, core-js-compat@^3.33.1: version "3.33.3" @@ -3762,6 +3769,14 @@ core-util-is@~1.0.0: resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz" integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== +cors@^2.8.5: + version "2.8.5" + resolved "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz" + integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g== + dependencies: + object-assign "^4" + vary "^1" + cosmiconfig@^6.0.0: version "6.0.0" resolved "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz" @@ -4318,9 +4333,9 @@ ee-first@1.1.1: integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== ejs@^3.1.6: - version "3.1.9" - resolved "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz" - integrity sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ== + version "3.1.10" + resolved "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz" + integrity sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA== dependencies: jake "^10.8.5" @@ -4883,16 +4898,16 @@ expect@^29.0.0, expect@^29.7.0: jest-util "^29.7.0" express@^4.17.3, express@^4.18.2: - version "4.18.2" - resolved "https://registry.npmjs.org/express/-/express-4.18.2.tgz" - integrity sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ== + version "4.19.2" + resolved "https://registry.npmjs.org/express/-/express-4.19.2.tgz" + integrity sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q== dependencies: accepts "~1.3.8" array-flatten "1.1.1" - body-parser "1.20.1" + body-parser "1.20.2" content-disposition "0.5.4" content-type "~1.0.4" - cookie "0.5.0" + cookie "0.6.0" cookie-signature "1.0.6" debug "2.6.9" depd "2.0.0" @@ -5001,10 +5016,10 @@ filesize@^8.0.6: resolved "https://registry.npmjs.org/filesize/-/filesize-8.0.7.tgz" integrity sha512-pjmC+bkIF8XI7fWaH8KxHcZL3DPybs1roSKP4rKDvy20tAWwIObE4+JIseG2byfGKhud5ZnM4YSGKBz7Sh0ndQ== -fill-range@^7.0.1: - version "7.0.1" - resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz" - integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== dependencies: to-regex-range "^5.0.1" @@ -5068,9 +5083,9 @@ flatted@^3.2.9: integrity sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ== follow-redirects@^1.0.0: - version "1.15.3" - resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz" - integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q== + version "1.15.6" + resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== for-each@^0.3.3: version "0.3.3" @@ -7378,6 +7393,15 @@ mongodb-connection-string-url@^3.0.0: "@types/whatwg-url" "^11.0.2" whatwg-url "^13.0.0" +mongodb@^6.7.0: + version "6.7.0" + resolved "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz" + integrity sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA== + dependencies: + "@mongodb-js/saslprep" "^1.1.5" + bson "^6.7.0" + mongodb-connection-string-url "^3.0.0" + mongodb@6.3.0: version "6.3.0" resolved "https://registry.npmjs.org/mongodb/-/mongodb-6.3.0.tgz" @@ -7414,7 +7438,7 @@ mqtt-packet@^9.0.0: debug "^4.3.4" process-nextick-args "^2.0.1" -mqtt@*, mqtt@^5.2.0: +mqtt@*, mqtt@^5.2.0, mqtt@^5.7.2: version "5.7.2" resolved "https://registry.npmjs.org/mqtt/-/mqtt-5.7.2.tgz" integrity sha512-b5xIA9J/K1LTubSWKaNYYLxYIusQdip6o9/8bRWad2TelRr8xLifjQt+SnamDAwMp3O6NdvR9E8ae7VMuN02kg== @@ -7590,7 +7614,7 @@ nwsapi@^2.2.0: resolved "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz" integrity sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ== -object-assign@^4.0.1, object-assign@^4.1.1: +object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz" integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg== @@ -8631,10 +8655,10 @@ range-parser@^1.2.1, range-parser@~1.2.1: resolved "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz" integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg== -raw-body@2.5.1: - version "2.5.1" - resolved "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz" - integrity sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig== +raw-body@2.5.2: + version "2.5.2" + resolved "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz" + integrity sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA== dependencies: bytes "3.1.2" http-errors "2.0.0" @@ -10254,6 +10278,11 @@ utils-merge@1.0.1: resolved "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz" integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA== +uuid@^10.0.0: + version "10.0.0" + resolved "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz" + integrity sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ== + uuid@^8.3.2: version "8.3.2" resolved "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz" @@ -10282,7 +10311,7 @@ v8-to-istanbul@^9.0.1: "@types/istanbul-lib-coverage" "^2.0.1" convert-source-map "^2.0.0" -vary@~1.1.2: +vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz" integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg== @@ -10351,9 +10380,9 @@ webidl-conversions@^7.0.0: integrity sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g== webpack-dev-middleware@^5.3.1: - version "5.3.3" - resolved "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz" - integrity sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA== + version "5.3.4" + resolved "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.4.tgz" + integrity sha512-BVdTqhhs+0IfoeAf7EoH5WE+exCmqGerHfDM0IL096Px60Tq2Mn9MAbnaGUe6HiMa41KMCYF19gyzZmBcq/o4Q== dependencies: colorette "^2.0.10" memfs "^3.4.3" @@ -10812,9 +10841,9 @@ write-file-atomic@^4.0.2: signal-exit "^3.0.7" ws@^7.4.6: - version "7.5.9" - resolved "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz" - integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== + version "7.5.10" + resolved "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz" + integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ== ws@^8.13.0, ws@^8.17.1: version "8.17.1" @@ -10900,4 +10929,4 @@ yn@3.1.1: yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz" - integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== \ No newline at end of file + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== From f4dca658f20dcf41d46ae7aca57ddcecacba6275 Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Sat, 22 Jun 2024 18:38:53 -0700 Subject: [PATCH 07/14] account.ts and docker-compose.yaml changes --- src/account/account.ts | 2 +- src/notification/docker-compose.yaml | 78 ++++++++++++++-------------- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/account/account.ts b/src/account/account.ts index e1a04008..44feaeeb 100644 --- a/src/account/account.ts +++ b/src/account/account.ts @@ -17,7 +17,7 @@ export const MICROSERVICE = config.microservice.account; export const PORT = config.microservice.port; // URL to mongoDB cluster -export const URL = `mongodb+srv://${USR}:${PSW}@${CLUS}.cgornhw.mongodb.net/Luminosity`; +export const URL = process.env.MONGO_DB_URL ?? ""; // Creates an Express application export const app = express(); diff --git a/src/notification/docker-compose.yaml b/src/notification/docker-compose.yaml index 650ca949..d44e4b1d 100644 --- a/src/notification/docker-compose.yaml +++ b/src/notification/docker-compose.yaml @@ -1,41 +1,43 @@ -version: "3" -services: - publish-service: - container_name: "publish-service" - build: - context: './publish' - env_file: - - ./.env - volumes: - - ./publish:/app - ports: - - 4000:4000 - networks: - - microservice - depends_on: - - activemq +# version: "3" +# services: +# publish-service: +# container_name: "publish-service" +# build: +# context: './publish' +# env_file: +# - ./.env +# volumes: +# - ./publish:/app +# ports: +# - 4000:4000 +# networks: +# - microservice +# depends_on: +# - activemq - subscribe-service: - container_name: subscribe-service - build: - context: './subscribe' - env_file: - - ./.env - volumes: - - ./subscribe:/app - networks: - - microservice - depends_on: - - activemq +# subscribe-service: +# container_name: subscribe-service +# build: +# context: './subscribe' +# env_file: +# - ./.env +# volumes: +# - ./subscribe:/app +# networks: +# - microservice +# depends_on: +# - activemq - activemq: - image: rmohr/activemq - container_name: activemq - networks: - - microservice - ports: - - "8161:8161" - - "1883:1883" +# activemq: +# image: rmohr/activemq +# container_name: activemq +# networks: +# - microservice +# ports: +# - "8161:8161" +# - "1883:1883" -networks: - microservice: \ No newline at end of file +# networks: +# microservice: + +# TODO: DEPRECATED/REMOVED AFTER VERSION 1.0 \ No newline at end of file From 8e34e9833fd0c8deb99694b96d2cc3c89e174a81 Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Sun, 23 Jun 2024 14:17:29 -0700 Subject: [PATCH 08/14] accountController and accountRoutes deleted, userController and userRoutes stay. routes.ts deprecated and server.ts updated. --- src/controllers/accountController.ts | 87 ------------- src/controllers/userController.ts | 3 + src/routes/accountRoutes.ts | 16 --- src/routes/routes.ts | 176 ++++++++++++++------------- src/routes/userRoutes.ts | 2 +- src/server/server.ts | 10 +- 6 files changed, 99 insertions(+), 195 deletions(-) delete mode 100644 src/controllers/accountController.ts delete mode 100644 src/routes/accountRoutes.ts diff --git a/src/controllers/accountController.ts b/src/controllers/accountController.ts deleted file mode 100644 index 90b3ee49..00000000 --- a/src/controllers/accountController.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Request, Response } from 'express'; -import Device from '../models/DeviceSchema'; // Import Device model -import User from '../models/UserSchema'; // Import User model - -// Register account -export const registerAccount = async (req: Request, res: Response) => { - try { - const { email, name, deletionDate, devicesLinked } = req.body; - const currentDate = new Date(); // Set current timestamp - const newAccountData = { - email, - name, - creationDate: currentDate, - lastUpdated: currentDate, - deletionDate: deletionDate ? new Date(deletionDate) : null, - }; - - const newAccount = new User(newAccountData); - - // Handle devicesLinked - if (devicesLinked && devicesLinked.length > 0) { - const devices = await Device.insertMany(devicesLinked); // Use Device to refer to the Device model - newAccount.devicesLinked = devices.map((device: any) => device._id); // Use explicit typing or adjust as needed - } else { - newAccount.devicesLinked = []; - } - - const savedAccount = await newAccount.save(); // Save the new account to the database - res.status(201).json(savedAccount); // HTTP 201 Created status code for successful creation - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } - }; - - // Get all accounts - export const getAllAccounts = async (_req: Request, res: Response) => { - try { - const events = await User.find(); // Use User model - res.json(events); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } - }; - - // Get account by ID - export const getAccountById = async (req: Request, res: Response) => { - try { - const event = await User.findById(req.params.id); // Use User model - - if (!event) { - res.status(404).json({ error: 'Event not found' }); - return; - } - - if (!req.params.id) { - res.status(400).json({ error: 'Bad Request' }); - return; - } - - res.json(event); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } - }; - - // Delete account by ID - export const deleteAccountById = async (req: Request, res: Response) => { - try { - const events = await User.findByIdAndDelete(req.params.id); // Use User model - - if (!events) { - // If the document doesn't exist, return a 404 Not Found response - res.status(404).json({ error: 'Event not found' }); - return; - } - - // If the document is successfully deleted, return a success message - res.json({ message: 'Event deleted successfully' }); - } catch (error) { - // If an error occurs during deletion, return a 500 Internal Server Error response - console.error(error); - res.status(500).json({ error: 'Internal Server Error' }); - } - }; \ No newline at end of file diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index efd31f8d..741c8b7e 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -31,6 +31,7 @@ export const registerUser = async (req: Request, res: Response): Promise = } }; +// Get all users export const getAllUsers = async (_req: Request, res: Response): Promise => { try { const users: UserInterface[] = await User.find().populate('devicesLinked'); @@ -41,6 +42,7 @@ export const getAllUsers = async (_req: Request, res: Response): Promise = } }; +// Get user by ID export const getUserById = async (req: Request, res: Response): Promise => { try { const user: UserInterface | null = await User.findById(req.params.id).populate('devicesLinked'); @@ -57,6 +59,7 @@ export const getUserById = async (req: Request, res: Response): Promise => } }; +// Delete user by ID export const deleteUserById = async (req: Request, res: Response): Promise => { try { const deletedUser: UserInterface | null = await User.findByIdAndDelete(req.params.id); diff --git a/src/routes/accountRoutes.ts b/src/routes/accountRoutes.ts deleted file mode 100644 index 43f44afc..00000000 --- a/src/routes/accountRoutes.ts +++ /dev/null @@ -1,16 +0,0 @@ -import express from 'express'; -import { - registerAccount, - getAllAccounts, - getAccountById, - deleteAccountById, -} from '../controllers/accountController'; - -const router = express.Router(); - -router.post('/accounts/new', registerAccount); -router.get('/accounts/all', getAllAccounts); -router.get('/accounts/:id', getAccountById); -router.delete('/accounts/:id/delete', deleteAccountById); - -export default router; diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 83f75884..a0ade696 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,99 +1,101 @@ -import express from 'express'; -const User = require('../models/UserSchema'); -import { publishRouter } from '../notification/publish/publish'; -import { subscribeRouter } from '../notification/subscribe/subscribe'; +// TODO: Remove, deprecate, or archive unused commented out code -const router = express.Router(); +// import express from 'express'; +// const User = require('../models/UserSchema'); +// import { publishRouter } from '../notification/publish/publish'; +// import { subscribeRouter } from '../notification/subscribe/subscribe'; -// Register method -router.post('/register', (req: any, res: any) => { - const { email, name, creationDate, lastUpdated, deletionDate, devicesLinked } = req.body; +// const router = express.Router(); - // Validate required fields - if (!email || !name || !creationDate || !lastUpdated) { - return res.status(400).json({ error: 'Missing required fields' }); - } +// // Register method +// router.post('/register', (req: any, res: any) => { +// const { email, name, creationDate, lastUpdated, deletionDate, devicesLinked } = req.body; - const user = new User({ - email, - name, - creationDate: new Date(creationDate), - lastUpdated: new Date(lastUpdated), - deletionDate: deletionDate ? new Date(deletionDate) : undefined, - devicesLinked: devicesLinked || [], - }); +// // Validate required fields +// if (!email || !name || !creationDate || !lastUpdated) { +// return res.status(400).json({ error: 'Missing required fields' }); +// } - user.save((err: any) => { - if (err) { - console.log(err); - return res.status(500).json({ error: 'Failed to register user' }); - } else { - return res.status(201).json({ message: 'User registered successfully' }); - } - }); -}); +// const user = new User({ +// email, +// name, +// creationDate: new Date(creationDate), +// lastUpdated: new Date(lastUpdated), +// deletionDate: deletionDate ? new Date(deletionDate) : undefined, +// devicesLinked: devicesLinked || [], +// }); -// Get all users method -router.get('/users', async (req: any, res: any) => { - try { - const users = await User.find(); - res.status(200).json(users); - } catch (err) { - res.status(500).json({ error: 'Failed to fetch users' }); - } -}); +// user.save((err: any) => { +// if (err) { +// console.log(err); +// return res.status(500).json({ error: 'Failed to register user' }); +// } else { +// return res.status(201).json({ message: 'User registered successfully' }); +// } +// }); +// }); -// Get one user by ID method -router.get('/users/:id', async (req: any, res: any) => { - try { - const user = await User.findById(req.params.id); - if (!user) { - return res.status(404).json({ error: 'User not found' }); - } - res.status(200).json(user); - } catch (err) { - res.status(500).json({ error: 'Failed to fetch user' }); - } -}); +// // Get all users method +// router.get('/users', async (req: any, res: any) => { +// try { +// const users = await User.find(); +// res.status(200).json(users); +// } catch (err) { +// res.status(500).json({ error: 'Failed to fetch users' }); +// } +// }); -// Update one user method -router.put('/users/:id', async (req: any, res: any) => { - try { - const updatedUser = await User.findByIdAndUpdate(req.params.id, req.body, { new: true }); - if (!updatedUser) { - return res.status(404).json({ error: 'User not found' }); - } - res.status(200).json(updatedUser); - } catch (err) { - res.status(500).json({ error: 'Failed to update user' }); - } -}); +// // Get one user by ID method +// router.get('/users/:id', async (req: any, res: any) => { +// try { +// const user = await User.findById(req.params.id); +// if (!user) { +// return res.status(404).json({ error: 'User not found' }); +// } +// res.status(200).json(user); +// } catch (err) { +// res.status(500).json({ error: 'Failed to fetch user' }); +// } +// }); -// Delete one user method -router.delete('/users/:id', async (req: any, res: any) => { - try { - const deletedUser = await User.findByIdAndDelete(req.params.id); - if (!deletedUser) { - return res.status(404).json({ error: 'User not found' }); - } - res.status(200).json({ message: 'User deleted' }); - } catch (err) { - res.status(500).json({ error: 'Failed to delete user' }); - } -}); +// // Update one user method +// router.put('/users/:id', async (req: any, res: any) => { +// try { +// const updatedUser = await User.findByIdAndUpdate(req.params.id, req.body, { new: true }); +// if (!updatedUser) { +// return res.status(404).json({ error: 'User not found' }); +// } +// res.status(200).json(updatedUser); +// } catch (err) { +// res.status(500).json({ error: 'Failed to update user' }); +// } +// }); -// Delete all users method -router.delete('/users', async (req: any, res: any) => { - try { - await User.deleteMany(); - res.status(200).json({ message: 'All users deleted' }); - } catch (err) { - res.status(500).json({ error: 'Failed to delete users' }); - } -}); +// // Delete one user method +// router.delete('/users/:id', async (req: any, res: any) => { +// try { +// const deletedUser = await User.findByIdAndDelete(req.params.id); +// if (!deletedUser) { +// return res.status(404).json({ error: 'User not found' }); +// } +// res.status(200).json({ message: 'User deleted' }); +// } catch (err) { +// res.status(500).json({ error: 'Failed to delete user' }); +// } +// }); -// Mount the publish and subscribe routers -router.use('/publish', publishRouter); -router.use('/subscribe', subscribeRouter); +// // Delete all users method +// router.delete('/users', async (req: any, res: any) => { +// try { +// await User.deleteMany(); +// res.status(200).json({ message: 'All users deleted' }); +// } catch (err) { +// res.status(500).json({ error: 'Failed to delete users' }); +// } +// }); -export default router; +// // Mount the publish and subscribe routers +// router.use('/publish', publishRouter); +// router.use('/subscribe', subscribeRouter); + +// export default router; diff --git a/src/routes/userRoutes.ts b/src/routes/userRoutes.ts index 00d6971e..a4586b72 100644 --- a/src/routes/userRoutes.ts +++ b/src/routes/userRoutes.ts @@ -3,7 +3,7 @@ import * as userController from '../controllers/userController'; const router = express.Router(); -// Define routes +// Define routes for users (formerly both user and account routes) router.post('/users/register', userController.registerUser); router.get('/users/all', userController.getAllUsers); router.get('/users/:id', userController.getUserById); diff --git a/src/server/server.ts b/src/server/server.ts index 91f1c2aa..7c87d885 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -3,8 +3,8 @@ import mongoose from "mongoose"; import dotenv from "dotenv"; import cors from "cors"; -import routeURLs from "../routes/routes"; -import accountRouter from "../routes/accountRoutes"; +// import routeURLs from "../routes/routes"; <- DEPRECATED +import userRouter from "../routes/userRoutes"; import publishRouter from "../routes/publishRoutes"; import subscribeRouter from "../routes/subscribeRoutes"; @@ -62,8 +62,10 @@ app.use(express.json()); app.use(cors()); // Route setup -app.use("/app", routeURLs); // Existing routes -app.use("/account", accountRouter); // Account service routes + +// app.use("/app", routeURLs); // Existing routes <- DEPRECATED + +app.use("/user", userRouter); // Account service routes app.use("/publish", publishRouter); // Publish service routes app.use("/subscribe", subscribeRouter); // Subscribe service routes From a4ad7eac9de5bcaa476dc355b6e4c1c9dc53eed4 Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Sun, 23 Jun 2024 16:43:40 -0700 Subject: [PATCH 09/14] Latest changes --- src/controllers/publishController.ts | 2 -- src/controllers/userController.ts | 22 +++++++++++++++++++--- src/notification/publish/publish.ts | 21 ++++++++++++++++++++- src/routes/userRoutes.ts | 10 +++++----- src/server/server.ts | 2 +- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/controllers/publishController.ts b/src/controllers/publishController.ts index bf5901d6..f748b261 100644 --- a/src/controllers/publishController.ts +++ b/src/controllers/publishController.ts @@ -4,8 +4,6 @@ import { v1 as uuidv1 } from 'uuid'; import mongoose from 'mongoose'; import dotenv from 'dotenv'; dotenv.config(); -import db from '../notification/publish/db'; // Import the db.ts file to access the dbURI variable - const options = { username: process.env.ACTIVE_MQ_USERNAME, diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 741c8b7e..34d4742e 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -8,6 +8,7 @@ export const registerUser = async (req: Request, res: Response): Promise = const { email, name, deletionDate, devicesLinked } = req.body; const currentDate = new Date(); + // Create a new user instance const newUser: UserInterface = new User({ email, name, @@ -17,12 +18,27 @@ export const registerUser = async (req: Request, res: Response): Promise = devicesLinked: [], // Initialize as an empty array }); + // Check if devicesLinked is provided and not empty if (devicesLinked && devicesLinked.length > 0) { - // Assuming devicesLinked is an array of objects that match DeviceInterface - const devices: any[] = await Device.insertMany(devicesLinked); // Cast to any[] temporarily - newUser.devicesLinked = devices.map((device: any) => device._id); // Map to _id + const savedDevices: DeviceInterface[] = []; + + // Iterate through devicesLinked array to create and save devices + for (const deviceData of devicesLinked) { + const newDeviceData: DeviceInterface = { + ...deviceData, + lastUpdated: currentDate, + }; + + const newDevice = new Device(newDeviceData); + const savedDevice = await newDevice.save(); + savedDevices.push(savedDevice); + } + + // Map the saved device IDs to newUser.devicesLinked + newUser.devicesLinked = savedDevices.map((device: DeviceInterface) => device._id); } + // Save the user with linked devices const savedUser: UserInterface = await newUser.save(); res.status(201).json(savedUser); } catch (error) { diff --git a/src/notification/publish/publish.ts b/src/notification/publish/publish.ts index 89b98ca4..2d773cf4 100644 --- a/src/notification/publish/publish.ts +++ b/src/notification/publish/publish.ts @@ -2,9 +2,14 @@ import mqtt, { MqttClient } from 'mqtt'; import { v1 as uuidv1 } from 'uuid'; import dotenv from 'dotenv'; import express from 'express'; +import mongoose, { ConnectOptions } from 'mongoose'; // Import mongoose for MongoDB connection +import dbConfig from './db'; // Import MongoDB configuration from db.ts dotenv.config(); +const app = express(); +const port = process.env.PORT || 4000; + const options = { username: process.env.ACTIVE_MQ_USERNAME, password: process.env.ACTIVE_MQ_PASSWORD, @@ -23,6 +28,16 @@ client.on('error', (error) => { console.error(error); }); +mongoose.connect(dbConfig.dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, +} as ConnectOptions).then(() => { + console.log('MongoDB connected'); +}).catch((err) => { + console.error('MongoDB connection error:', err); + process.exit(1); // Exit process on connection error +}); + const publishRouter = express.Router(); publishRouter.post('/publish', (req, res) => { @@ -42,4 +57,8 @@ publishRouter.post('/publish', (req, res) => { }); }); -export { publishRouter }; +app.use('/publish', publishRouter); + +app.listen(port, () => { + console.log(`Publish service is running on port ${port}`); +}); diff --git a/src/routes/userRoutes.ts b/src/routes/userRoutes.ts index a4586b72..db4ee3c8 100644 --- a/src/routes/userRoutes.ts +++ b/src/routes/userRoutes.ts @@ -3,10 +3,10 @@ import * as userController from '../controllers/userController'; const router = express.Router(); -// Define routes for users (formerly both user and account routes) -router.post('/users/register', userController.registerUser); -router.get('/users/all', userController.getAllUsers); -router.get('/users/:id', userController.getUserById); -router.delete('/users/:id/delete', userController.deleteUserById); +// Define routes for users +router.post('/register', userController.registerUser); +router.get('/all', userController.getAllUsers); +router.get('/:id', userController.getUserById); +router.delete('/:id/delete', userController.deleteUserById); export default router; diff --git a/src/server/server.ts b/src/server/server.ts index 7c87d885..c4b5fb77 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -65,7 +65,7 @@ app.use(cors()); // app.use("/app", routeURLs); // Existing routes <- DEPRECATED -app.use("/user", userRouter); // Account service routes +app.use("/users", userRouter); // User service routes app.use("/publish", publishRouter); // Publish service routes app.use("/subscribe", subscribeRouter); // Subscribe service routes From 6af4352626ff58275c7b8b7adcdd0ddc68c9aee6 Mon Sep 17 00:00:00 2001 From: pogi7 Date: Sun, 23 Jun 2024 21:41:41 -0700 Subject: [PATCH 10/14] fix 404 error w/ publish/:id Signed-off-by: pogi7 --- docker-compose.yaml | 4 ++ src/account/Dockerfile | 2 +- src/notification/publish/Dockerfile | 2 +- src/notification/publish/publish.ts | 55 ++++++++++----------------- src/notification/subscribe/Dockerfile | 2 +- 5 files changed, 27 insertions(+), 38 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index ea5c5f6a..a6137a45 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -37,6 +37,8 @@ services: build: context: 'src/notification/publish' env_file: ".env" + volumes: + - ./src/notification/publish:/app ports: - 4000:4000 networks: @@ -49,6 +51,8 @@ services: build: context: 'src/notification/subscribe' env_file: ".env" + volumes: + - ./src/notification/subscribe:/app networks: - backend depends_on: diff --git a/src/account/Dockerfile b/src/account/Dockerfile index 89e0a029..538ecdb7 100644 --- a/src/account/Dockerfile +++ b/src/account/Dockerfile @@ -1,5 +1,5 @@ # Base image for account microservice. This image uses amd64 as the architecture -FROM amd64/node:18-bullseye +FROM node:18-bullseye # Specifies root of file structure as working directory in docker image WORKDIR / diff --git a/src/notification/publish/Dockerfile b/src/notification/publish/Dockerfile index e28abcaa..552157f3 100644 --- a/src/notification/publish/Dockerfile +++ b/src/notification/publish/Dockerfile @@ -1,5 +1,5 @@ # Base image for publish notification microservice. This image uses amd64 as the architecture -FROM amd64/node:18-bullseye +FROM node:18-bullseye # Specifies app directory as working directory in docker image WORKDIR /app diff --git a/src/notification/publish/publish.ts b/src/notification/publish/publish.ts index 2d773cf4..e63de814 100644 --- a/src/notification/publish/publish.ts +++ b/src/notification/publish/publish.ts @@ -18,46 +18,31 @@ const options = { }; const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion -const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); - -client.on('connect', () => { - console.log("Broker connected"); -}); - -client.on('error', (error) => { - console.error(error); -}); - -mongoose.connect(dbConfig.dbURI, { - useNewUrlParser: true, - useUnifiedTopology: true, -} as ConnectOptions).then(() => { - console.log('MongoDB connected'); -}).catch((err) => { - console.error('MongoDB connection error:', err); - process.exit(1); // Exit process on connection error -}); - -const publishRouter = express.Router(); - -publishRouter.post('/publish', (req, res) => { +app.get("/publish/:id", async (req, res) => { + const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); // Type assertion const event = { - id: uuidv1(), - message: "Hello from Publish Service", + id: req.params.id, + message: "From Publish Service", }; - client.publish(topic, JSON.stringify(event), {}, (err) => { - if (err) { - console.error(`Error publishing message: ${err}`); - res.status(500).json({ error: 'Failed to publish message' }); - } else { - console.log(`Published message: ${JSON.stringify(event)} to topic ${topic}`); - res.status(200).json({ message: 'Message published successfully' }); - } + client.on('connect', () => { + console.log("Broker connected"); + client.publish(topic, JSON.stringify(event), {}, (err) => { + if (err) { + console.error(`Error publishing message: ${err}`); + res.status(500).json({ error: 'Internal Server Error' }); + } else { + client.end(); + res.json(event); + } + }); }); -}); -app.use('/publish', publishRouter); + client.on('error', (error) => { + console.log(error); + res.status(500).json({ error: 'Internal Server Error' }); + }); +}); app.listen(port, () => { console.log(`Publish service is running on port ${port}`); diff --git a/src/notification/subscribe/Dockerfile b/src/notification/subscribe/Dockerfile index f2d9b10f..fce04fdb 100644 --- a/src/notification/subscribe/Dockerfile +++ b/src/notification/subscribe/Dockerfile @@ -1,5 +1,5 @@ # Base image for subscribe notification microservice. This image uses amd64 as the architecture -FROM amd64/node:18-bullseye +FROM node:18-bullseye # Specifies app directory as working directory in docker image WORKDIR /app From 9d82fbe83fd3fec2851b51dcf856a941d7dfcc8d Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Sun, 23 Jun 2024 22:57:28 -0700 Subject: [PATCH 11/14] Latest changes --- docker-compose.yaml | 22 ++++++++--------- src/controllers/publishController.ts | 17 -------------- src/controllers/userController.ts | 12 ++++++++-- src/models/DeviceSchema.ts | 6 ++--- src/notification/publish/Dockerfile | 4 ++-- src/notification/publish/publish.ts | 26 ++++++++++++++++++--- src/server/server.ts | 35 +++++++++++++++++----------- 7 files changed, 70 insertions(+), 52 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index a6137a45..dfa3cc72 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,16 +11,16 @@ services: - "1883:1883" env_file: ".env" - # server: - # build: "." - # command: "npm run server" - # ports: - # - "4000:4000" - # networks: - # - backend - # env_file: ".env" - # depends_on: - # - "activemq" + server: + build: "." + command: "npm run server" + ports: + - "4000:4000" + networks: + - backend + env_file: ".env" + depends_on: + - "activemq" account: container_name: "account" build: "src/account/" @@ -40,7 +40,7 @@ services: volumes: - ./src/notification/publish:/app ports: - - 4000:4000 + - 6000:6000 networks: - backend depends_on: diff --git a/src/controllers/publishController.ts b/src/controllers/publishController.ts index f748b261..9446749f 100644 --- a/src/controllers/publishController.ts +++ b/src/controllers/publishController.ts @@ -1,7 +1,6 @@ import { Request, Response } from 'express'; import mqtt, { MqttClient } from 'mqtt'; import { v1 as uuidv1 } from 'uuid'; -import mongoose from 'mongoose'; import dotenv from 'dotenv'; dotenv.config(); @@ -13,22 +12,6 @@ const options = { }; const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion -// Establish Mongoose connection -// MongoDB URL -const URL = process.env.MONGO_DB_URL; - -// Verify that URL is defined -if (URL) { - const mongo_connect = mongoose.createConnection(URL); - mongo_connect.on(`error`, console.error.bind(console, `connection error:`)); - mongo_connect.once(`open`, () => { - // Successful connection! - console.log("MongoDB database connection established successfully"); - }); -} else { - console.error("MongoDB URL is not defined in .env file."); -} - // Publish message to MQTT export const publishMessage = async (req: Request, res: Response) => { const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 34d4742e..a360d7d5 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -39,10 +39,18 @@ export const registerUser = async (req: Request, res: Response): Promise = } // Save the user with linked devices - const savedUser: UserInterface = await newUser.save(); + let savedUser: UserInterface | null = await newUser.save(); + + // Populate the devicesLinked field + savedUser = await User.findById(savedUser._id).populate('devicesLinked').exec(); + + if (!savedUser) { + throw new Error('User not found after saving'); + } + res.status(201).json(savedUser); } catch (error) { - console.error(error); + console.error('Error saving user:', error); res.status(500).json({ error: 'Internal Server Error' }); } }; diff --git a/src/models/DeviceSchema.ts b/src/models/DeviceSchema.ts index 7c07f65f..fa1fab6c 100644 --- a/src/models/DeviceSchema.ts +++ b/src/models/DeviceSchema.ts @@ -8,7 +8,7 @@ export interface DeviceInterface extends Document { connected?: boolean; connectedTimestamp?: Date | null; color?: string; - colorTimestamp?: string; + colorTimestamp?: Date | null; // Corrected to Date brightness?: number; brightnessTimestamp?: Date | null; } @@ -21,7 +21,7 @@ const DeviceSchema: Schema = new mongoose.Schema({ }, lastUpdated: { type: Date, - default: new Date(), + default: Date.now, // Corrected to use Date.now required: true, }, powered: { @@ -40,7 +40,7 @@ const DeviceSchema: Schema = new mongoose.Schema({ type: String, }, colorTimestamp: { - type: String, + type: Date, // Corrected to Date }, brightness: { type: Number, diff --git a/src/notification/publish/Dockerfile b/src/notification/publish/Dockerfile index 552157f3..07fe85f5 100644 --- a/src/notification/publish/Dockerfile +++ b/src/notification/publish/Dockerfile @@ -4,8 +4,8 @@ FROM node:18-bullseye # Specifies app directory as working directory in docker image WORKDIR /app -# Exposes port 4000 which is the same port specified in the express app in publish.ts -EXPOSE 4000 +# Exposes port 6000 which is the same port specified in the express app in publish.ts +EXPOSE 6000 # Copy config files to app directory in docker image COPY package.json /app/ diff --git a/src/notification/publish/publish.ts b/src/notification/publish/publish.ts index e63de814..6a284b26 100644 --- a/src/notification/publish/publish.ts +++ b/src/notification/publish/publish.ts @@ -2,13 +2,13 @@ import mqtt, { MqttClient } from 'mqtt'; import { v1 as uuidv1 } from 'uuid'; import dotenv from 'dotenv'; import express from 'express'; -import mongoose, { ConnectOptions } from 'mongoose'; // Import mongoose for MongoDB connection -import dbConfig from './db'; // Import MongoDB configuration from db.ts +import mongoose, { ConnectOptions } from "mongoose"; +import dbConfig from './db'; // Import MongoDB configuration from db.t dotenv.config(); const app = express(); -const port = process.env.PORT || 4000; +const port = process.env.PORT || 6000; const options = { username: process.env.ACTIVE_MQ_USERNAME, @@ -18,6 +18,26 @@ const options = { }; const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion +// MongoDB connection setup +async function connectToMongoDB() { + try { + await mongoose.connect(dbConfig.dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, + } as ConnectOptions); + console.log('Connected to MongoDB'); + } catch (error) { + console.error(`Error connecting to MongoDB: ${error}`); + process.exit(1); // Exit process on connection error + } +} + +// Connect to MongoDB and start the server +connectToMongoDB().catch(error => { + console.error(`Error starting Publish service: ${error}`); + process.exit(1); // Exit process if MongoDB connection or server startup fails +}); + app.get("/publish/:id", async (req, res) => { const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); // Type assertion const event = { diff --git a/src/server/server.ts b/src/server/server.ts index c4b5fb77..9996ffe8 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -1,5 +1,5 @@ import express from "express"; -import mongoose from "mongoose"; +import mongoose, { ConnectOptions } from "mongoose"; import dotenv from "dotenv"; import cors from "cors"; @@ -8,6 +8,8 @@ import userRouter from "../routes/userRoutes"; import publishRouter from "../routes/publishRoutes"; import subscribeRouter from "../routes/subscribeRoutes"; +import dbConfig from '../notification/publish/db'; // Import MongoDB configuration from db.ts + // TODO: Remove, deprecate, or archive unused commented out code // dotenv.config(); @@ -42,21 +44,26 @@ dotenv.config(); const app = express(); const port = process.env.PORT || 4000; -// MongoDB URL -const URL = process.env.MONGO_DB_URL; - -// Verify that URL is defined -if (URL) { - const mongo_connect = mongoose.createConnection(URL); - mongo_connect.on(`error`, console.error.bind(console, `connection error:`)); - mongo_connect.once(`open`, () => { - // Successful connection! - console.log("MongoDB database connection established successfully"); - }); -} else { - console.error("MongoDB URL is not defined in .env file."); +// MongoDB connection setup +async function connectToMongoDB() { + try { + await mongoose.connect(dbConfig.dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, + } as ConnectOptions); + console.log('Connected to MongoDB'); + } catch (error) { + console.error(`Error connecting to MongoDB: ${error}`); + process.exit(1); // Exit process on connection error + } } +// Connect to MongoDB and start the server +connectToMongoDB().catch(error => { + console.error(`Error starting Publish service: ${error}`); + process.exit(1); // Exit process if MongoDB connection or server startup fails +}); + // Middleware setup app.use(express.json()); app.use(cors()); From 8a494c525b849f6b3e3a6ac195c3cd5e2686d55b Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Mon, 24 Jun 2024 22:09:02 -0700 Subject: [PATCH 12/14] Latest changes --- docker-compose.yaml | 4 ++- src/controllers/subscribeController.ts | 33 +++++++++++++------------ src/controllers/userController.ts | 16 +++++++++--- src/notification/subscribe/Dockerfile | 3 +++ src/notification/subscribe/db.ts | 18 ++++++++++++++ src/notification/subscribe/subscribe.ts | 29 +++++++++++++++++++++- src/routes/publishRoutes.ts | 4 +-- src/server/server.ts | 2 +- 8 files changed, 84 insertions(+), 25 deletions(-) create mode 100644 src/notification/subscribe/db.ts diff --git a/docker-compose.yaml b/docker-compose.yaml index dfa3cc72..2f411d49 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -47,12 +47,14 @@ services: - activemq subscribe: - container_name: subscribe + container_name: "subscribe" build: context: 'src/notification/subscribe' env_file: ".env" volumes: - ./src/notification/subscribe:/app + ports: + - 7000:7000 networks: - backend depends_on: diff --git a/src/controllers/subscribeController.ts b/src/controllers/subscribeController.ts index eb3b2da1..17f9142c 100644 --- a/src/controllers/subscribeController.ts +++ b/src/controllers/subscribeController.ts @@ -27,26 +27,27 @@ client.on('message', async (receivedTopic, msg) => { console.log(`Message received: ${message}`); // MongoDB logic for handling received message - try { - interface Subscription extends Document { - id: string; - message: string; - } + try { + interface SubscriptionInterface extends Document { + id: string; + message: string; + } - const subscriptionSchema = new Schema({ - id: String, - message: String, - }); + const subscriptionSchema = new Schema({ + id: String, + message: String, + }); - const SubscriptionModel = mongoose.model('Subscription', subscriptionSchema); + // Check if the model already exists before defining it + const SubscriptionModel = mongoose.models.Subscription || mongoose.model('Subscription', subscriptionSchema); - const subscription = { - id: uuidv4(), - message: message, - }; + const subscription = { + id: uuidv4(), + message: message, + }; - await SubscriptionModel.create(subscription); - } catch (error) { + await SubscriptionModel.create(subscription); +} catch (error) { // Simulate a 404 error if (!message) { diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index a360d7d5..dd93cb21 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -86,14 +86,24 @@ export const getUserById = async (req: Request, res: Response): Promise => // Delete user by ID export const deleteUserById = async (req: Request, res: Response): Promise => { try { - const deletedUser: UserInterface | null = await User.findByIdAndDelete(req.params.id); + // Find the user by ID + const user: UserInterface | null = await User.findById(req.params.id); - if (!deletedUser) { + if (!user) { res.status(404).json({ error: 'User not found' }); return; } - res.json({ message: 'User deleted successfully' }); + // Delete associated devices + const deviceIds = user.devicesLinked; + if (deviceIds.length > 0) { + await Device.deleteMany({ _id: { $in: deviceIds } }); + } + + // Delete the user + const deletedUser: UserInterface | null = await User.findByIdAndDelete(req.params.id); + + res.json({ message: 'User and associated devices deleted successfully' }); } catch (error) { console.error(error); res.status(500).json({ error: 'Internal Server Error' }); diff --git a/src/notification/subscribe/Dockerfile b/src/notification/subscribe/Dockerfile index fce04fdb..1299f17a 100644 --- a/src/notification/subscribe/Dockerfile +++ b/src/notification/subscribe/Dockerfile @@ -4,6 +4,9 @@ FROM node:18-bullseye # Specifies app directory as working directory in docker image WORKDIR /app +# Exposes port 7000 which is the same port specified in the express app in subscribe.ts +EXPOSE 7000 + # Copy config files to app directory in docker image COPY package.json /app/ diff --git a/src/notification/subscribe/db.ts b/src/notification/subscribe/db.ts new file mode 100644 index 00000000..1d19dd0d --- /dev/null +++ b/src/notification/subscribe/db.ts @@ -0,0 +1,18 @@ +import mongoose from 'mongoose'; +import dotenv from 'dotenv'; +dotenv.config(); + +const dbURI = `mongodb+srv://${process.env.MONGO_DB_USER}:${process.env.MONGO_DB_PASS}@luminositycluster-0.cgornhw.mongodb.net/Luminosity`; //MongoDb Connection String + +mongoose.connect(dbURI); + +const db = mongoose.connection; + +db.on('error', console.error.bind(console, 'MongoDB connection error:')); +db.once('open', () => { + console.log('Connected to MongoDB'); +}); + +export default { + dbURI +}; \ No newline at end of file diff --git a/src/notification/subscribe/subscribe.ts b/src/notification/subscribe/subscribe.ts index 172cd009..b2681c5e 100644 --- a/src/notification/subscribe/subscribe.ts +++ b/src/notification/subscribe/subscribe.ts @@ -1,9 +1,14 @@ import mqtt, { MqttClient } from 'mqtt'; import dotenv from 'dotenv'; import express from 'express'; +import mongoose, { ConnectOptions } from "mongoose"; +import dbConfig from './db'; // Import MongoDB configuration from db.ts dotenv.config(); +const app = express(); +const port = process.env.PORT || 7000; + const options = { username: process.env.ACTIVE_MQ_USERNAME, password: process.env.ACTIVE_MQ_PASSWORD, @@ -14,6 +19,26 @@ const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); +// MongoDB connection setup +async function connectToMongoDB() { + try { + await mongoose.connect(dbConfig.dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, + } as ConnectOptions); + console.log('Connected to MongoDB'); + } catch (error) { + console.error(`Error connecting to MongoDB: ${error}`); + process.exit(1); // Exit process on connection error + } +} + +// Connect to MongoDB and start the server +connectToMongoDB().catch(error => { + console.error(`Error starting Subscribe service: ${error}`); + process.exit(1); // Exit process if MongoDB connection or server startup fails +}); + client.on('connect', () => { console.log("Broker connected"); client.subscribe(topic, (err) => { @@ -42,4 +67,6 @@ const subscribeRouter = express.Router(); // res.send('Subscribe endpoint'); // }); -export { subscribeRouter }; \ No newline at end of file +app.listen(port, () => { + console.log(`Subscribe service is running on port ${port}`); +}); diff --git a/src/routes/publishRoutes.ts b/src/routes/publishRoutes.ts index f14bb0f8..fd5ad1ea 100644 --- a/src/routes/publishRoutes.ts +++ b/src/routes/publishRoutes.ts @@ -1,7 +1,5 @@ import express from 'express'; -import { - publishMessage, -} from '../controllers/publishController'; +import { publishMessage } from '../controllers/publishController'; const router = express.Router(); diff --git a/src/server/server.ts b/src/server/server.ts index 9996ffe8..23615d09 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -60,7 +60,7 @@ async function connectToMongoDB() { // Connect to MongoDB and start the server connectToMongoDB().catch(error => { - console.error(`Error starting Publish service: ${error}`); + console.error(`Error starting Server service: ${error}`); process.exit(1); // Exit process if MongoDB connection or server startup fails }); From a23e4bd30d6227a9667cda086761537d09b25b1b Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Mon, 24 Jun 2024 22:23:10 -0700 Subject: [PATCH 13/14] subscribe.ts fixes --- src/notification/subscribe/subscribe.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/notification/subscribe/subscribe.ts b/src/notification/subscribe/subscribe.ts index b2681c5e..801addec 100644 --- a/src/notification/subscribe/subscribe.ts +++ b/src/notification/subscribe/subscribe.ts @@ -1,6 +1,7 @@ import mqtt, { MqttClient } from 'mqtt'; import dotenv from 'dotenv'; import express from 'express'; +import { Request, Response } from 'express'; import mongoose, { ConnectOptions } from "mongoose"; import dbConfig from './db'; // Import MongoDB configuration from db.ts @@ -61,11 +62,12 @@ client.on('error', (error) => { const subscribeRouter = express.Router(); -// Define subscription routes if needed -// Example: -// subscribeRouter.get('/subscribe', (req, res) => { -// res.send('Subscribe endpoint'); -// }); +// Check subscription status +subscribeRouter.get('/status', (req: Request, res: Response) => { + res.status(200).json({ message: 'Subscriber is running' }); +}); + +app.use('/subscribe', subscribeRouter); app.listen(port, () => { console.log(`Subscribe service is running on port ${port}`); From 3260614810ee8ad75b2cbc4f78e6f0d0e9e6590d Mon Sep 17 00:00:00 2001 From: Kevin Babakhani Date: Sun, 30 Jun 2024 23:01:04 -0700 Subject: [PATCH 14/14] Latest changes --- src/controllers/publishController.ts | 74 ++++++++------- src/controllers/subscribeController.ts | 120 ++++++++++++------------ src/db.ts | 30 ++++++ src/notification/publish/db.ts | 30 ++++-- src/notification/publish/publish.ts | 23 +---- src/notification/subscribe/db.ts | 30 ++++-- src/notification/subscribe/subscribe.ts | 25 +---- src/routes/publishRoutes.ts | 12 ++- src/routes/subscribeRoutes.ts | 12 ++- src/server/server.ts | 25 +---- src/tsconfig.json | 5 +- 11 files changed, 201 insertions(+), 185 deletions(-) create mode 100644 src/db.ts diff --git a/src/controllers/publishController.ts b/src/controllers/publishController.ts index 9446749f..effd24db 100644 --- a/src/controllers/publishController.ts +++ b/src/controllers/publishController.ts @@ -1,41 +1,43 @@ -import { Request, Response } from 'express'; -import mqtt, { MqttClient } from 'mqtt'; -import { v1 as uuidv1 } from 'uuid'; -import dotenv from 'dotenv'; -dotenv.config(); +// TODO: Remove, deprecate, or archive unused commented out code -const options = { - username: process.env.ACTIVE_MQ_USERNAME, - password: process.env.ACTIVE_MQ_PASSWORD, - clientId: `publish_${uuidv1()}`, - port: 1883, -}; -const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion +// import { Request, Response } from 'express'; +// import mqtt, { MqttClient } from 'mqtt'; +// import { v1 as uuidv1 } from 'uuid'; +// import dotenv from 'dotenv'; +// dotenv.config(); -// Publish message to MQTT -export const publishMessage = async (req: Request, res: Response) => { - const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); +// const options = { +// username: process.env.ACTIVE_MQ_USERNAME, +// password: process.env.ACTIVE_MQ_PASSWORD, +// clientId: `publish_${uuidv1()}`, +// port: 1883, +// }; +// const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion - const event = { - id: req.params.id, - message: "From Publish Service", - }; +// // Publish message to MQTT +// export const publishMessage = async (req: Request, res: Response) => { +// const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); - client.on('connect', () => { - console.log("Broker connected"); - client.publish(topic, JSON.stringify(event), {}, (err) => { - if (err) { - console.error(`Error publishing message: ${err}`); - res.status(500).json({ error: 'Internal Server Error' }); - } else { - client.end(); - res.json(event); - } - }); - }); +// const event = { +// id: req.params.id, +// message: "From Publish Service", +// }; - client.on('error', (error) => { - console.log(error); - res.status(500).json({ error: 'Internal Server Error' }); - }); -}; +// client.on('connect', () => { +// console.log("Broker connected"); +// client.publish(topic, JSON.stringify(event), {}, (err) => { +// if (err) { +// console.error(`Error publishing message: ${err}`); +// res.status(500).json({ error: 'Internal Server Error' }); +// } else { +// client.end(); +// res.json(event); +// } +// }); +// }); + +// client.on('error', (error) => { +// console.log(error); +// res.status(500).json({ error: 'Internal Server Error' }); +// }); +// }; diff --git a/src/controllers/subscribeController.ts b/src/controllers/subscribeController.ts index 17f9142c..41888378 100644 --- a/src/controllers/subscribeController.ts +++ b/src/controllers/subscribeController.ts @@ -1,74 +1,76 @@ -import { Request, Response } from 'express'; -import mqtt, { MqttClient } from 'mqtt'; -import { v4 as uuidv4 } from 'uuid'; -import mongoose, { Schema, Document } from 'mongoose'; -import dotenv from 'dotenv'; -dotenv.config(); +// // TODO: Remove, deprecate, or archive unused commented out code -const options = { - username: process.env.ACTIVE_MQ_USERNAME, - password: process.env.ACTIVE_MQ_PASSWORD, - clientId: `subscribe_${uuidv4()}`, - port: 1883, -}; +// import { Request, Response } from 'express'; +// import mqtt, { MqttClient } from 'mqtt'; +// import { v4 as uuidv4 } from 'uuid'; +// import mongoose, { Schema, Document } from 'mongoose'; +// import dotenv from 'dotenv'; +// dotenv.config(); -const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion -const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); // Type assertion +// const options = { +// username: process.env.ACTIVE_MQ_USERNAME, +// password: process.env.ACTIVE_MQ_PASSWORD, +// clientId: `subscribe_${uuidv4()}`, +// port: 1883, +// }; -client.on('connect', () => { - client.subscribe(topic); -}); +// const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion +// const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); // Type assertion -let message: string | null = null; +// client.on('connect', () => { +// client.subscribe(topic); +// }); -client.on('message', async (receivedTopic, msg) => { - console.log(`Message received on topic ${receivedTopic}`); - message = msg.toString(); - console.log(`Message received: ${message}`); +// let message: string | null = null; - // MongoDB logic for handling received message - try { - interface SubscriptionInterface extends Document { - id: string; - message: string; - } +// client.on('message', async (receivedTopic, msg) => { +// console.log(`Message received on topic ${receivedTopic}`); +// message = msg.toString(); +// console.log(`Message received: ${message}`); - const subscriptionSchema = new Schema({ - id: String, - message: String, - }); +// // MongoDB logic for handling received message +// try { +// interface SubscriptionInterface extends Document { +// id: string; +// message: string; +// } - // Check if the model already exists before defining it - const SubscriptionModel = mongoose.models.Subscription || mongoose.model('Subscription', subscriptionSchema); +// const subscriptionSchema = new Schema({ +// id: String, +// message: String, +// }); - const subscription = { - id: uuidv4(), - message: message, - }; +// // Check if the model already exists before defining it +// const SubscriptionModel = mongoose.models.Subscription || mongoose.model('Subscription', subscriptionSchema); - await SubscriptionModel.create(subscription); -} catch (error) { +// const subscription = { +// id: uuidv4(), +// message: message, +// }; - // Simulate a 404 error - if (!message) { - throw { status: 404, message: 'Not Found' }; - } +// await SubscriptionModel.create(subscription); +// } catch (error) { - // Simulate a 403 error - if (message === 'Forbidden') { - throw { status: 403, message: 'Forbidden' }; - } +// // Simulate a 404 error +// if (!message) { +// throw { status: 404, message: 'Not Found' }; +// } - // Simulate a 401 error - if (message === 'Unauthorized') { - throw { status: 401, message: 'Unauthorized' }; - } +// // Simulate a 403 error +// if (message === 'Forbidden') { +// throw { status: 403, message: 'Forbidden' }; +// } + +// // Simulate a 401 error +// if (message === 'Unauthorized') { +// throw { status: 401, message: 'Unauthorized' }; +// } - console.error(error); - } -}); +// console.error(error); +// } +// }); -// Check subscription status -export const checkSubscriptionStatus = (req: Request, res: Response) => { - res.status(200).json({ message: 'Subscriber is running' }); -}; +// // Check subscription status +// export const checkSubscriptionStatus = (req: Request, res: Response) => { +// res.status(200).json({ message: 'Subscriber is running' }); +// }; diff --git a/src/db.ts b/src/db.ts new file mode 100644 index 00000000..4b0d974e --- /dev/null +++ b/src/db.ts @@ -0,0 +1,30 @@ +import mongoose from 'mongoose'; +import dotenv from 'dotenv'; + +dotenv.config(); + +const dbURI = `mongodb+srv://${process.env.MONGO_DB_USER}:${process.env.MONGO_DB_PASS}@luminositycluster-0.cgornhw.mongodb.net/Luminosity`; + +let isConnected = false; + +export const connectToMongoDB = async () => { + if (isConnected) { + console.log('MongoDB connection is already established'); + return; + } + + try { + await mongoose.connect(dbURI, { + }); + isConnected = true; + console.log('Connected to MongoDB'); + } catch (error) { + console.error(`Error connecting to MongoDB: ${error}`); + process.exit(1); // Exit process on connection error + } +}; + +export default { + dbURI, + connectToMongoDB +}; diff --git a/src/notification/publish/db.ts b/src/notification/publish/db.ts index 1d19dd0d..4b0d974e 100644 --- a/src/notification/publish/db.ts +++ b/src/notification/publish/db.ts @@ -1,18 +1,30 @@ import mongoose from 'mongoose'; import dotenv from 'dotenv'; + dotenv.config(); -const dbURI = `mongodb+srv://${process.env.MONGO_DB_USER}:${process.env.MONGO_DB_PASS}@luminositycluster-0.cgornhw.mongodb.net/Luminosity`; //MongoDb Connection String +const dbURI = `mongodb+srv://${process.env.MONGO_DB_USER}:${process.env.MONGO_DB_PASS}@luminositycluster-0.cgornhw.mongodb.net/Luminosity`; -mongoose.connect(dbURI); +let isConnected = false; -const db = mongoose.connection; +export const connectToMongoDB = async () => { + if (isConnected) { + console.log('MongoDB connection is already established'); + return; + } -db.on('error', console.error.bind(console, 'MongoDB connection error:')); -db.once('open', () => { - console.log('Connected to MongoDB'); -}); + try { + await mongoose.connect(dbURI, { + }); + isConnected = true; + console.log('Connected to MongoDB'); + } catch (error) { + console.error(`Error connecting to MongoDB: ${error}`); + process.exit(1); // Exit process on connection error + } +}; export default { - dbURI -}; \ No newline at end of file + dbURI, + connectToMongoDB +}; diff --git a/src/notification/publish/publish.ts b/src/notification/publish/publish.ts index 6a284b26..dc4222f6 100644 --- a/src/notification/publish/publish.ts +++ b/src/notification/publish/publish.ts @@ -2,8 +2,7 @@ import mqtt, { MqttClient } from 'mqtt'; import { v1 as uuidv1 } from 'uuid'; import dotenv from 'dotenv'; import express from 'express'; -import mongoose, { ConnectOptions } from "mongoose"; -import dbConfig from './db'; // Import MongoDB configuration from db.t +import { connectToMongoDB } from './db'; // Import the singleton connection function dotenv.config(); @@ -16,21 +15,7 @@ const options = { clientId: `publish_${uuidv1()}`, port: 1883, }; -const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion - -// MongoDB connection setup -async function connectToMongoDB() { - try { - await mongoose.connect(dbConfig.dbURI, { - useNewUrlParser: true, - useUnifiedTopology: true, - } as ConnectOptions); - console.log('Connected to MongoDB'); - } catch (error) { - console.error(`Error connecting to MongoDB: ${error}`); - process.exit(1); // Exit process on connection error - } -} +const topic = process.env.ACTIVE_MQ_TOPIC as string; // Connect to MongoDB and start the server connectToMongoDB().catch(error => { @@ -39,7 +24,7 @@ connectToMongoDB().catch(error => { }); app.get("/publish/:id", async (req, res) => { - const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); // Type assertion + const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); const event = { id: req.params.id, message: "From Publish Service", @@ -58,7 +43,7 @@ app.get("/publish/:id", async (req, res) => { }); }); - client.on('error', (error) => { + client.on('error', (error: Error) => { console.log(error); res.status(500).json({ error: 'Internal Server Error' }); }); diff --git a/src/notification/subscribe/db.ts b/src/notification/subscribe/db.ts index 1d19dd0d..4b0d974e 100644 --- a/src/notification/subscribe/db.ts +++ b/src/notification/subscribe/db.ts @@ -1,18 +1,30 @@ import mongoose from 'mongoose'; import dotenv from 'dotenv'; + dotenv.config(); -const dbURI = `mongodb+srv://${process.env.MONGO_DB_USER}:${process.env.MONGO_DB_PASS}@luminositycluster-0.cgornhw.mongodb.net/Luminosity`; //MongoDb Connection String +const dbURI = `mongodb+srv://${process.env.MONGO_DB_USER}:${process.env.MONGO_DB_PASS}@luminositycluster-0.cgornhw.mongodb.net/Luminosity`; -mongoose.connect(dbURI); +let isConnected = false; -const db = mongoose.connection; +export const connectToMongoDB = async () => { + if (isConnected) { + console.log('MongoDB connection is already established'); + return; + } -db.on('error', console.error.bind(console, 'MongoDB connection error:')); -db.once('open', () => { - console.log('Connected to MongoDB'); -}); + try { + await mongoose.connect(dbURI, { + }); + isConnected = true; + console.log('Connected to MongoDB'); + } catch (error) { + console.error(`Error connecting to MongoDB: ${error}`); + process.exit(1); // Exit process on connection error + } +}; export default { - dbURI -}; \ No newline at end of file + dbURI, + connectToMongoDB +}; diff --git a/src/notification/subscribe/subscribe.ts b/src/notification/subscribe/subscribe.ts index 801addec..e9d78b4c 100644 --- a/src/notification/subscribe/subscribe.ts +++ b/src/notification/subscribe/subscribe.ts @@ -2,8 +2,7 @@ import mqtt, { MqttClient } from 'mqtt'; import dotenv from 'dotenv'; import express from 'express'; import { Request, Response } from 'express'; -import mongoose, { ConnectOptions } from "mongoose"; -import dbConfig from './db'; // Import MongoDB configuration from db.ts +import { connectToMongoDB } from './db'; // Import the singleton connection function dotenv.config(); @@ -13,27 +12,13 @@ const port = process.env.PORT || 7000; const options = { username: process.env.ACTIVE_MQ_USERNAME, password: process.env.ACTIVE_MQ_PASSWORD, - clientId: `subscribe_${Math.random().toString(16).substr(2, 8)}`, // Generate random client ID + clientId: `subscribe_${Math.random().toString(16).substr(2, 8)}`, port: 1883, }; -const topic = process.env.ACTIVE_MQ_TOPIC as string; // Type assertion +const topic = process.env.ACTIVE_MQ_TOPIC as string; const client: MqttClient = mqtt.connect(process.env.ACTIVE_MQ_ENDPOINT as string, options); -// MongoDB connection setup -async function connectToMongoDB() { - try { - await mongoose.connect(dbConfig.dbURI, { - useNewUrlParser: true, - useUnifiedTopology: true, - } as ConnectOptions); - console.log('Connected to MongoDB'); - } catch (error) { - console.error(`Error connecting to MongoDB: ${error}`); - process.exit(1); // Exit process on connection error - } -} - // Connect to MongoDB and start the server connectToMongoDB().catch(error => { console.error(`Error starting Subscribe service: ${error}`); @@ -53,16 +38,14 @@ client.on('connect', () => { client.on('message', (topic, message) => { console.log(`Received message from topic ${topic}: ${message.toString()}`); - // Process the received message as needed }); -client.on('error', (error) => { +client.on('error', (error: Error) => { console.error(error); }); const subscribeRouter = express.Router(); -// Check subscription status subscribeRouter.get('/status', (req: Request, res: Response) => { res.status(200).json({ message: 'Subscriber is running' }); }); diff --git a/src/routes/publishRoutes.ts b/src/routes/publishRoutes.ts index fd5ad1ea..e7fc7f21 100644 --- a/src/routes/publishRoutes.ts +++ b/src/routes/publishRoutes.ts @@ -1,8 +1,10 @@ -import express from 'express'; -import { publishMessage } from '../controllers/publishController'; +// TODO: Remove, deprecate, or archive unused commented out code -const router = express.Router(); +// import express from 'express'; +// import { publishMessage } from '../controllers/publishController'; -router.get('/:id', publishMessage); +// const router = express.Router(); -export default router; +// router.get('/:id', publishMessage); + +// export default router; diff --git a/src/routes/subscribeRoutes.ts b/src/routes/subscribeRoutes.ts index d2bfd3c1..5099bc3f 100644 --- a/src/routes/subscribeRoutes.ts +++ b/src/routes/subscribeRoutes.ts @@ -1,8 +1,10 @@ -import express from 'express'; -import { checkSubscriptionStatus } from '../controllers/subscribeController'; +// TODO: Remove, deprecate, or archive unused commented out code -const router = express.Router(); +// import express from 'express'; +// import { checkSubscriptionStatus } from '../controllers/subscribeController'; -router.get('/status', checkSubscriptionStatus); +// const router = express.Router(); -export default router; +// router.get('/status', checkSubscriptionStatus); + +// export default router; diff --git a/src/server/server.ts b/src/server/server.ts index 23615d09..0fee5dc9 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -1,14 +1,13 @@ import express from "express"; -import mongoose, { ConnectOptions } from "mongoose"; import dotenv from "dotenv"; import cors from "cors"; // import routeURLs from "../routes/routes"; <- DEPRECATED import userRouter from "../routes/userRoutes"; -import publishRouter from "../routes/publishRoutes"; -import subscribeRouter from "../routes/subscribeRoutes"; +// import publishRouter from "../routes/publishRoutes"; <- DEPRECATED +// import subscribeRouter from "../routes/subscribeRoutes"; <- DEPRECATED -import dbConfig from '../notification/publish/db'; // Import MongoDB configuration from db.ts +import { connectToMongoDB } from '../db'; // Import the singleton connection function // TODO: Remove, deprecate, or archive unused commented out code // dotenv.config(); @@ -44,20 +43,6 @@ dotenv.config(); const app = express(); const port = process.env.PORT || 4000; -// MongoDB connection setup -async function connectToMongoDB() { - try { - await mongoose.connect(dbConfig.dbURI, { - useNewUrlParser: true, - useUnifiedTopology: true, - } as ConnectOptions); - console.log('Connected to MongoDB'); - } catch (error) { - console.error(`Error connecting to MongoDB: ${error}`); - process.exit(1); // Exit process on connection error - } -} - // Connect to MongoDB and start the server connectToMongoDB().catch(error => { console.error(`Error starting Server service: ${error}`); @@ -73,8 +58,8 @@ app.use(cors()); // app.use("/app", routeURLs); // Existing routes <- DEPRECATED app.use("/users", userRouter); // User service routes -app.use("/publish", publishRouter); // Publish service routes -app.use("/subscribe", subscribeRouter); // Subscribe service routes +// app.use("/publish", publishRouter); // Publish service routes <- DEPRECATED +// app.use("/subscribe", subscribeRouter); // Subscribe service routes <- DEPRECATED // Start the server app.listen(port, () => { diff --git a/src/tsconfig.json b/src/tsconfig.json index c93d9d18..3557cff5 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -76,7 +76,8 @@ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ + "strict": true, + /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ @@ -99,5 +100,5 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + } } \ No newline at end of file