diff --git a/.gitignore b/.gitignore index 9f1f131d6..df54c0e01 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vite \ No newline at end of file +.vite +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 82af5013d..9d362d5c3 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ BlueWave uptime monitoring application #### Installation 1. Change directory to the `Server` directory -2. Install all depencies by running `npm install` +2. Install all dependencies by running `npm install` --- @@ -39,14 +39,14 @@ BlueWave uptime monitoring application Configure the server with the following environmental variables -| ENV Varialbe Name | Required/Optional | Type | Description | Accepted Values | -| -------------------- | ----------------- | --------- | ---------------------------------------------------- | ------------------- | -| JWT_SECRET | Required | `string` | JWT secret | | -| DB_TYPE | Optional | `string` | Specify DB to use | `MongoDB \| FakeDB` | -| DB_CONNECTION_STRING | Required | `string` | Specfies URL for MongoDB Database | | -| PORT | Optional | `integer` | Specifies Port for Server | | -| MAILERSEND_API_KEY | Required | `string` | Specfies API KEY for MailerSend service | | -| SYSTEM_EMAIL_ADDRESS | Required | `string` | Specfies System email to be used in emailing service | | +| ENV Variable Name | Required/Optional | Type | Description | Accepted Values | +| -------------------- | ----------------- | --------- | ----------------------------------------------------- | ------------------- | +| JWT_SECRET | Required | `string` | JWT secret | | +| DB_TYPE | Optional | `string` | Specify DB to use | `MongoDB \| FakeDB` | +| DB_CONNECTION_STRING | Required | `string` | Specifies URL for MongoDB Database | | +| PORT | Optional | `integer` | Specifies Port for Server | | +| MAILERSEND_API_KEY | Required | `string` | Specifies API KEY for MailerSend service | | +| SYSTEM_EMAIL_ADDRESS | Required | `string` | Specifies System email to be used in emailing service | | --- @@ -154,18 +154,8 @@ curl --request POST \ ```json { "success": true, - "msg": "User created}", - "data": { - "_id": "6645079aae0b439371913972", - "firstname": "User First Name", - "lastname": "User Last Name", - "email": "user@gmail.com", - "isActive": true, - "isVerified": false, - "updated_at": "2024-05-15T19:06:02.720Z", - "created_at": "2024-05-15T19:06:02.720Z", - "__v": 0 - } + "msg": "User created", + "data": "" } ``` @@ -214,7 +204,7 @@ curl --request POST \ { "success": true, "msg": "Found user", - "data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NjQ1MDc5YWFlMGI0MzkzNzE5MTM5NzIiLCJmaXJzdG5hbWUiOiJBbGV4IiwibGFzdG5hbWUiOiJIb2xsaWRheSIsImVtYWlsIjoiYWpob2xsaWRAZ21haWwuY29tIiwiaXNBY3RpdmUiOnRydWUsImlzVmVyaWZpZWQiOmZhbHNlLCJ1cGRhdGVkX2F0IjoiMjAyNC0wNS0xNVQxOTowNjowMi43MjBaIiwiY3JlYXRlZF9hdCI6IjIwMjQtMDUtMTVUMTk6MDY6MDIuNzIwWiIsIl9fdiI6MCwiaWF0IjoxNzE2Mzk5MDM2fQ.clFR01gh5XK9DtLjB-_JLxMBAzBZuduRQv3ZzqHuTRY" + "data": "" } ``` @@ -237,6 +227,49 @@ curl --request POST \ > | ---------------- | ----------------- | > | `Array[Monitor]` | Array of monitors | +###### Sample cURL Request + +``` +curl --request GET \ + --url http://localhost:5000/api/v1/monitors \ + --header '' \ +``` + +###### Sample Response + +```json +{ + "success": true, + "msg": "Monitors found", + "data": [ + { + "_id": "664d070786e62625ac612ca1", + "userId": "6645079aae0b439371913972", + "name": "Wha3", + "description": "Description", + "url": "https://monitor0.com", + "isActive": true, + "interval": 60000, + "createdAt": "2024-05-21T20:41:43.051Z", + "updatedAt": "2024-05-21T20:45:10.496Z", + "__v": 0 + }, + { + "_id": "664e5ccf189c864800debc16", + "userId": "6645079aae0b439371913972", + "name": "Inserting a new Monitor", + "description": "Description", + "url": "https://monitor0.com", + "isActive": true, + "interval": 60000, + "createdAt": "2024-05-22T20:59:59.295Z", + "updatedAt": "2024-05-22T20:59:59.295Z", + "__v": 0 + } + ] +} +``` + --- @@ -256,6 +289,35 @@ curl --request POST \ > | --------- | --------------------------------------------------- | > | `Monitor` | Single monitor with the id in the request parameter | +###### Sample cURL Request + +``` +curl --request GET \ + --url http://localhost:5000/api/v1/monitors/664d070786e62625ac612ca1 \ + --header '' \ +``` + +###### Sample Response + +```json +{ + "success": true, + "msg": "Monitor found", + "data": { + "_id": "664d070786e62625ac612ca1", + "userId": "6645079aae0b439371913972", + "name": "My Monitor", + "description": "Description", + "url": "https://monitor0.com", + "isActive": true, + "interval": 60000, + "createdAt": "2024-05-21T20:41:43.051Z", + "updatedAt": "2024-05-21T20:45:10.496Z", + "__v": 0 + } +} +``` + --- @@ -269,14 +331,197 @@ curl --request POST \ > | -------------- | ----- | > | Method | GET | -###### Request Payload +###### Response Payload > | Type | Notes | > | ---------------- | ------------------------------------------------------------------ | > | `Array[Monitor]` | Array of monitors created by user with userId specified in request | +###### Sample cURL Request + +``` +curl --request GET \ + --url http://localhost:5000/api/v1/monitors/user/6645079aae0b439371913972 \ + --header '' \ +``` + +###### Sample Response + +```json +{ + "success": true, + "msg": "Monitors for user 6645079aae0b439371913972 found", + "data": [ + { + "_id": "664d070786e62625ac612ca1", + "userId": "6645079aae0b439371913972", + "name": "Wha3", + "description": "Description", + "url": "https://monitor0.com", + "isActive": true, + "interval": 60000, + "createdAt": "2024-05-21T20:41:43.051Z", + "updatedAt": "2024-05-21T20:45:10.496Z", + "__v": 0 + }, + { + "_id": "664e5ccf189c864800debc16", + "userId": "6645079aae0b439371913972", + "name": "Inserting a new Monitor", + "description": "Description", + "url": "https://monitor0.com", + "isActive": true, + "interval": 60000, + "createdAt": "2024-05-22T20:59:59.295Z", + "updatedAt": "2024-05-22T20:59:59.295Z", + "__v": 0 + } + ] +} +``` + +--- + +
+POST/api/v1/monitors + +###### Method/Headers + +> | Method/Headers | Value | +> | -------------- | ----- | +> | Method | POST | + +###### Response Payload + +> | Type | Notes | +> | --------- | --------------------------------- | +> | `Monitor` | Newly created monitor is returned | + +##### Sample CURL request + +``` +curl --request POST \ + --url http://localhost:5000/api/v1/monitors \ + --header \ + --header 'Content-Type: application/json' \ + --data '{"userId": "6645079aae0b439371913972", + "name": "Inserting a new Monitor", + "description": "Description", + "url": "https://monitor0.com", + "isActive": true, + "interval": 60000}' +``` + +##### Sample Response + +```json +{ + "success": true, + "msg": "Monitor created", + "data": { + "userId": "6645079aae0b439371913972", + "name": "Inserting a new Monitor", + "description": "Description", + "url": "https://monitor0.com", + "isActive": true, + "interval": 60000, + "_id": "664e5ccf189c864800debc16", + "createdAt": "2024-05-22T20:59:59.295Z", + "updatedAt": "2024-05-22T20:59:59.295Z", + "__v": 0 + } +} +``` + +
+ +--- + +
+POST/api/v1/monitors/delete/{monitorId} + +###### Method/Headers + +> | Method/Headers | Value | +> | -------------- | ----- | +> | Method | POST | + +###### Response Payload + +> | Type | Notes | +> | ---- | ------------------- | +> | None | No payload returned | + +##### Sample CURL request + +``` +curl --request POST \ + --url http://localhost:5000/api/v1/monitors/delete/664e632a7a3ee9d620761938 \ + --header '' \ + --header 'Content-Type: application/json' \ +``` + +##
+ +--- + +
+POST/api/v1/monitors/edit/{monitorId} + +###### Method/Headers + +> | Method/Headers | Value | +> | -------------- | ----- | +> | Method | POST | + +###### Response Payload + +> | Type | Notes | +> | --------- | --------------------------- | +> | `Monitor` | Returns the updated monitor | + +##### Sample CURL request + +``` +curl --request POST \ + --url http://localhost:5000/api/v1/monitors/edit/664e5ccf189c864800debc16 \ + --header ' diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index 90a12e244..1285726e1 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -57,7 +57,7 @@ const registerController = async (req, res) => { service: SERVICE_NAME, userId: newUser._id, }); - const token = issueToken(newUser); + const token = issueToken(newUser._doc); return res .status(200) diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 3a46427c4..cf245fba3 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -41,8 +41,7 @@ const getMonitorById = async (req, res) => { } try { - const monitorId = req.params.monitorId; - const monitor = await req.db.getMonitorById(monitorId); + const monitor = await req.db.getMonitorById(req, res); return res.json({ success: true, msg: "Monitor found", data: monitor }); } catch (error) { logger.error(error.message, { service: "monitor" }); @@ -68,7 +67,7 @@ const getMonitorsByUserId = async (req, res) => { try { const userId = req.params.userId; - const monitors = await req.db.getMonitorsByUserId(userId); + const monitors = await req.db.getMonitorsByUserId(req, res); logger.info(`Monitors for user ${userId} found`, { service: "monitor", userId: userId,