Merge branch 'master' into feat/alert-routes

This commit is contained in:
Alex Holliday committed 2024-05-28 11:17:42 -07:00
commit db13b71157
5 files changed
+254 -25

No files matched your search

+117 -25
View File
@@ -10,15 +10,21 @@ BlueWave uptime monitoring application
2. [Installation (Server)](#server)
3. [Configuration(Server)](#config-server)
4. [Endpoints](#endpoints)
###### Auth
- <code>POST</code> [/api/v1/auth/register](#post-register)
- <code>POST</code> [/api/v1/auth/login](#post-login)
- <code>POST</code> [/api/v1/auth/user/{userId}](#post-auth-user-edit-id)
###### Monitors
- <code>GET</code> [/api/v1/monitors](#get-monitors)
- <code>GET</code> [/api/v1/monitor/{id}](#get-monitor-id)
- <code>GET</code> [/api/v1/monitors/user/{userId}](#get-monitors-user-userid)
- <code>POST</code> [/api/v1/monitors](#post-monitors)
- <code>POST</code> [/api/v1/monitors/delete/{monitorId}](#post-monitors-del-id)
- <code>POST</code> [/api/v1/monitors/edit/{monitorId}](#post-monitors-edit-id)
###### Checks
- <code>POST</code> [/api/v1/checks/{monitorId}](#post-checks)
- <code>GET</code> [/api/v1/checks/{monitorId}](#get-checks)
- <code>POST</code> [/api/v1/checks/delete/{monitorId}](#delete-checks)
5. [Error Handling](#error-handling)
6. [Contributors](#contributors)
@@ -122,15 +128,15 @@ Example:
<details>
<summary><code>Check</code></summary>
| Name | Type | Notes |
| ----------- | --------- | ------------------------------------------------|
| monitorId | `string` | Unique ID for the monitor |
| status | `boolean` | Indicates the service is Up or Down |
| responseTime| `integer` | Indicates the response time of the service (ms) |
| statusCode | `integer` | Status Code returned from the service |
| message | `string` | Message returned from the service |
| updatedAt | `Date` | Last time the check was updated |
| CreatedAt | `Date` | When the check was created |
| Name | Type | Notes |
| ------------ | --------- | ----------------------------------------------- |
| monitorId | `string` | Unique ID for the monitor |
| status | `boolean` | Indicates the service is Up or Down |
| responseTime | `integer` | Indicates the response time of the service (ms) |
| statusCode | `integer` | Status Code returned from the service |
| message | `string` | Message returned from the service |
| updatedAt | `Date` | Last time the check was updated |
| CreatedAt | `Date` | When the check was created |
</details>
@@ -138,9 +144,9 @@ Example:
<summary><code>Alert</code></summary>
| Name | Type | Notes |
| ----------- | --------- | --------------------------------------------------|
| ----------------- | --------- | ------------------------------------------------- |
| checkId | `string` | Unique ID for the check |
| status | `boolean` | Indicates the service is Up or Down |
| status | `boolean` | Indicates the service is Up or Down |
| message | `string` | Message for the user about the down service |
| notifiedStatus | `boolean` | Indicates whether the user is notified |
| acknowledgeStatus | `boolean` | Indicates whether the user acknowledged the alert |
@@ -148,8 +154,11 @@ Example:
| CreatedAt | `Date` | When the alert was created |
</details>
---
###### Auth
<details>
<summary id='post-register'><code>POST</code> <b>/api/v1/auth/register</b></summary>
@@ -201,8 +210,6 @@ curl --request POST \
</details>
---
<details>
<summary id='post-login'><code>POST</code> <b>/api/v1/auth/login</b></summary>
@@ -250,8 +257,6 @@ curl --request POST \
</details>
---
<details>
<summary id='post-auth-user-edit-id'><code>POST</code><b>/api/v1/auth/user/{userId}</b></summary>
@@ -313,6 +318,8 @@ curl --request POST \
---
###### Monitors
<details>
<summary id='get-monitors'><code>GET</code> <b>/api/v1/monitors</b></summary>
@@ -373,8 +380,6 @@ curl --request GET \
</details>
---
<details>
<summary id='get-monitor-id'><code>GET</code> <b>/api/v1/monitor/{id}</b></summary>
@@ -421,8 +426,6 @@ curl --request GET \
</details>
---
<details>
<summary id='get-monitors-user-userid'><code>GET</code> <b>/api/v1/monitors/user/{userId}</b></summary>
@@ -483,8 +486,6 @@ curl --request GET \
</details>
---
<details>
<summary id='post-monitors'><code>POST</code><b>/api/v1/monitors</b></summary>
@@ -538,8 +539,6 @@ curl --request POST \
</details>
---
<details>
<summary id='post-monitors-del-id'><code>POST</code><b>/api/v1/monitors/delete/{monitorId}</b></summary>
@@ -575,8 +574,6 @@ curl --request POST \
## </details>
---
<details>
<summary id='post-monitors-edit-id'><code>POST</code><b>/api/v1/monitors/edit/{monitorId}</b></summary>
@@ -636,6 +633,101 @@ curl --request POST \
---
###### Checks
<details>
<summary id='post-checks'><code>POST</code><b>/api/v1/checks/{monitorId}</b></summary>
###### Method/Headers
> | Method/Headers | Value |
> | -------------- | ----- |
> | Method | POST |
###### Response Payload
> | Type | Notes |
> | ---- | ------------------- |
> | None | No payload returned |
###### Body
##### Sample CURL request
```
```
###### Sample Response
```json
```
</details>
<details>
<summary id='get-checks'><code>GET</code><b>/api/v1/checks/{monitorId}</b></summary>
###### Method/Headers
> | Method/Headers | Value |
> | -------------- | ----- |
> | Method | POST |
###### Response Payload
> | Type | Notes |
> | --------------- | ------------------------ |
> | `Array[Checks]` | Array of `Check` objects |
##### Sample CURL request
```
```
###### Sample Response
```json
```
</details>
<details>
<summary id='delete-checks'><code>POST</code><b>/api/v1/checks/delete/{monitorId}</b></summary>
###### Method/Headers
> | Method/Headers | Value |
> | -------------- | ----- |
> | Method | POST |
###### Response Payload
> | Type | Notes |
> | ---- | ------------------- |
> | None | No payload returned |
###### Body
##### Sample CURL request
```
```
###### Sample Response
```json
```
</details>
---
### Error handling {#error-handling}
Errors are returned in a standard format:
+37
View File
@@ -0,0 +1,37 @@
var jwt = require("jsonwebtoken");
const SERVICE_NAME = "check";
const createCheck = (req, res, next) => {
try {
req.db.createCheck(req, res);
} catch (error) {
error.service = SERVICE_NAME;
next(error);
}
};
const getChecks = (req, res, next) => {
try {
req.db.getChecks(req, res);
// Return all checks for a monitor
} catch (error) {
error.service = SERVICE_NAME;
next(error);
}
};
const deleteChecks = (req, res, next) => {
try {
req.db.deleteChecks(req, res);
// Delete all checks for a monitor
} catch (error) {
error.service = SERVICE_NAME;
next(error);
}
};
module.exports = {
createCheck,
getChecks,
deleteChecks,
};
+74
View File
@@ -16,6 +16,10 @@ const connect = async () => {
}
};
//****************************************
// Users
//****************************************
/**
* Insert a User
* @async
@@ -55,6 +59,10 @@ const getUserByEmail = async (req, res) => {
}
};
//****************************************
// Monitors
//****************************************
/**
* Update a user by ID
* @async
@@ -194,6 +202,69 @@ const editMonitor = async (req, res) => {
}
};
//****************************************
// Checks
//****************************************
/**
* Create a check for a monitor
* @async
* @param {Express.Request} req
* @param {Express.Response} res
* @throws {Error}
*/
const createCheck = async (req, res) => {
try {
// Create check with monitor id
res
.status(200)
.json({ success: true, msg: "Create check", data: req.params.monitorId });
} catch (error) {
throw error;
}
};
/**
* Get all checks for a monitor
* @async
* @param {Express.Request} req
* @param {Express.Response} res
* @throws {Error}
*/
const getChecks = async (req, res) => {
try {
// TODO get all checks for a monitor from DB
res
.status(200)
.json({ success: true, msg: "Get checks", data: req.params.monitorId });
} catch (error) {
throw error;
}
};
/**
* Delete all checks for a monitor
* @async
* @param {Express.Request} req
* @param {Express.Response} res
* @throws {Error}
*/
const deleteChecks = async (req, res) => {
try {
// TODO Delete all checks for a monitor
res.status(200).json({
success: true,
msg: "Deleted checks",
data: req.params.monitorId,
});
} catch (error) {
throw error;
}
};
module.exports = {
connect,
insertUser,
@@ -205,4 +276,7 @@ module.exports = {
createMonitor,
deleteMonitor,
editMonitor,
createCheck,
getChecks,
deleteChecks,
};
+2
View File
@@ -3,6 +3,7 @@ const helmet = require("helmet");
const cors = require("cors");
const authRouter = require("./routes/authRoute");
const monitorRouter = require("./routes/monitorRoute");
const checkRouter = require("./routes/checkRoute");
const { connectDbAndRunServer } = require("./configs/db");
require("dotenv").config();
const logger = require("./utils/logger");
@@ -62,6 +63,7 @@ app.use((req, res, next) => {
//routes
app.use("/api/v1/auth", authRouter);
app.use("/api/v1/monitors", verifyJWT, monitorRouter);
app.use("/api/v1/checks", verifyJWT, checkRouter);
// Testing email service
// app.use('/sendEmail', async (req, res) => {
+24
View File
@@ -0,0 +1,24 @@
const router = require("express").Router();
const checkController = require("../controllers/checkController");
const { verifyOwnership } = require("../middleware/verifyOwnership");
const Monitor = require("../models/Monitor");
router.post(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
checkController.createCheck
);
router.get(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
checkController.getChecks
);
router.post(
"/delete/:monitorId",
verifyOwnership(Monitor, "monitorId"),
checkController.deleteChecks
);
module.exports = router;