Merge branch 'master' into feat/alert-routes
This commit is contained in:
commit
db13b71157
5 files changed
+254
-25
No files matched your search
@@ -10,15 +10,21 @@ BlueWave uptime monitoring application
|
|||||||
2. [Installation (Server)](#server)
|
2. [Installation (Server)](#server)
|
||||||
3. [Configuration(Server)](#config-server)
|
3. [Configuration(Server)](#config-server)
|
||||||
4. [Endpoints](#endpoints)
|
4. [Endpoints](#endpoints)
|
||||||
|
###### Auth
|
||||||
- <code>POST</code> [/api/v1/auth/register](#post-register)
|
- <code>POST</code> [/api/v1/auth/register](#post-register)
|
||||||
- <code>POST</code> [/api/v1/auth/login](#post-login)
|
- <code>POST</code> [/api/v1/auth/login](#post-login)
|
||||||
- <code>POST</code> [/api/v1/auth/user/{userId}](#post-auth-user-edit-id)
|
- <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/monitors](#get-monitors)
|
||||||
- <code>GET</code> [/api/v1/monitor/{id}](#get-monitor-id)
|
- <code>GET</code> [/api/v1/monitor/{id}](#get-monitor-id)
|
||||||
- <code>GET</code> [/api/v1/monitors/user/{userId}](#get-monitors-user-userid)
|
- <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](#post-monitors)
|
||||||
- <code>POST</code> [/api/v1/monitors/delete/{monitorId}](#post-monitors-del-id)
|
- <code>POST</code> [/api/v1/monitors/delete/{monitorId}](#post-monitors-del-id)
|
||||||
- <code>POST</code> [/api/v1/monitors/edit/{monitorId}](#post-monitors-edit-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)
|
5. [Error Handling](#error-handling)
|
||||||
6. [Contributors](#contributors)
|
6. [Contributors](#contributors)
|
||||||
|
|
||||||
@@ -122,15 +128,15 @@ Example:
|
|||||||
<details>
|
<details>
|
||||||
<summary><code>Check</code></summary>
|
<summary><code>Check</code></summary>
|
||||||
|
|
||||||
| Name | Type | Notes |
|
| Name | Type | Notes |
|
||||||
| ----------- | --------- | ------------------------------------------------|
|
| ------------ | --------- | ----------------------------------------------- |
|
||||||
| monitorId | `string` | Unique ID for the monitor |
|
| monitorId | `string` | Unique ID for the monitor |
|
||||||
| status | `boolean` | Indicates the service is Up or Down |
|
| status | `boolean` | Indicates the service is Up or Down |
|
||||||
| responseTime| `integer` | Indicates the response time of the service (ms) |
|
| responseTime | `integer` | Indicates the response time of the service (ms) |
|
||||||
| statusCode | `integer` | Status Code returned from the service |
|
| statusCode | `integer` | Status Code returned from the service |
|
||||||
| message | `string` | Message returned from the service |
|
| message | `string` | Message returned from the service |
|
||||||
| updatedAt | `Date` | Last time the check was updated |
|
| updatedAt | `Date` | Last time the check was updated |
|
||||||
| CreatedAt | `Date` | When the check was created |
|
| CreatedAt | `Date` | When the check was created |
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@@ -138,9 +144,9 @@ Example:
|
|||||||
<summary><code>Alert</code></summary>
|
<summary><code>Alert</code></summary>
|
||||||
|
|
||||||
| Name | Type | Notes |
|
| Name | Type | Notes |
|
||||||
| ----------- | --------- | --------------------------------------------------|
|
| ----------------- | --------- | ------------------------------------------------- |
|
||||||
| checkId | `string` | Unique ID for the check |
|
| 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 |
|
| message | `string` | Message for the user about the down service |
|
||||||
| notifiedStatus | `boolean` | Indicates whether the user is notified |
|
| notifiedStatus | `boolean` | Indicates whether the user is notified |
|
||||||
| acknowledgeStatus | `boolean` | Indicates whether the user acknowledged the alert |
|
| acknowledgeStatus | `boolean` | Indicates whether the user acknowledged the alert |
|
||||||
@@ -148,8 +154,11 @@ Example:
|
|||||||
| CreatedAt | `Date` | When the alert was created |
|
| CreatedAt | `Date` | When the alert was created |
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
###### Auth
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='post-register'><code>POST</code> <b>/api/v1/auth/register</b></summary>
|
<summary id='post-register'><code>POST</code> <b>/api/v1/auth/register</b></summary>
|
||||||
|
|
||||||
@@ -201,8 +210,6 @@ curl --request POST \
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='post-login'><code>POST</code> <b>/api/v1/auth/login</b></summary>
|
<summary id='post-login'><code>POST</code> <b>/api/v1/auth/login</b></summary>
|
||||||
|
|
||||||
@@ -250,8 +257,6 @@ curl --request POST \
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='post-auth-user-edit-id'><code>POST</code><b>/api/v1/auth/user/{userId}</b></summary>
|
<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>
|
<details>
|
||||||
<summary id='get-monitors'><code>GET</code> <b>/api/v1/monitors</b></summary>
|
<summary id='get-monitors'><code>GET</code> <b>/api/v1/monitors</b></summary>
|
||||||
|
|
||||||
@@ -373,8 +380,6 @@ curl --request GET \
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='get-monitor-id'><code>GET</code> <b>/api/v1/monitor/{id}</b></summary>
|
<summary id='get-monitor-id'><code>GET</code> <b>/api/v1/monitor/{id}</b></summary>
|
||||||
|
|
||||||
@@ -421,8 +426,6 @@ curl --request GET \
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='get-monitors-user-userid'><code>GET</code> <b>/api/v1/monitors/user/{userId}</b></summary>
|
<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>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='post-monitors'><code>POST</code><b>/api/v1/monitors</b></summary>
|
<summary id='post-monitors'><code>POST</code><b>/api/v1/monitors</b></summary>
|
||||||
|
|
||||||
@@ -538,8 +539,6 @@ curl --request POST \
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='post-monitors-del-id'><code>POST</code><b>/api/v1/monitors/delete/{monitorId}</b></summary>
|
<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>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary id='post-monitors-edit-id'><code>POST</code><b>/api/v1/monitors/edit/{monitorId}</b></summary>
|
<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}
|
### Error handling {#error-handling}
|
||||||
|
|
||||||
Errors are returned in a standard format:
|
Errors are returned in a standard format:
|
||||||
|
|||||||
@@ -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,
|
||||||
|
};
|
||||||
@@ -16,6 +16,10 @@ const connect = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
// Users
|
||||||
|
//****************************************
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a User
|
* Insert a User
|
||||||
* @async
|
* @async
|
||||||
@@ -55,6 +59,10 @@ const getUserByEmail = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
// Monitors
|
||||||
|
//****************************************
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a user by ID
|
* Update a user by ID
|
||||||
* @async
|
* @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 = {
|
module.exports = {
|
||||||
connect,
|
connect,
|
||||||
insertUser,
|
insertUser,
|
||||||
@@ -205,4 +276,7 @@ module.exports = {
|
|||||||
createMonitor,
|
createMonitor,
|
||||||
deleteMonitor,
|
deleteMonitor,
|
||||||
editMonitor,
|
editMonitor,
|
||||||
|
createCheck,
|
||||||
|
getChecks,
|
||||||
|
deleteChecks,
|
||||||
};
|
};
|
||||||
@@ -3,6 +3,7 @@ const helmet = require("helmet");
|
|||||||
const cors = require("cors");
|
const cors = require("cors");
|
||||||
const authRouter = require("./routes/authRoute");
|
const authRouter = require("./routes/authRoute");
|
||||||
const monitorRouter = require("./routes/monitorRoute");
|
const monitorRouter = require("./routes/monitorRoute");
|
||||||
|
const checkRouter = require("./routes/checkRoute");
|
||||||
const { connectDbAndRunServer } = require("./configs/db");
|
const { connectDbAndRunServer } = require("./configs/db");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const logger = require("./utils/logger");
|
const logger = require("./utils/logger");
|
||||||
@@ -62,6 +63,7 @@ app.use((req, res, next) => {
|
|||||||
//routes
|
//routes
|
||||||
app.use("/api/v1/auth", authRouter);
|
app.use("/api/v1/auth", authRouter);
|
||||||
app.use("/api/v1/monitors", verifyJWT, monitorRouter);
|
app.use("/api/v1/monitors", verifyJWT, monitorRouter);
|
||||||
|
app.use("/api/v1/checks", verifyJWT, checkRouter);
|
||||||
|
|
||||||
// Testing email service
|
// Testing email service
|
||||||
// app.use('/sendEmail', async (req, res) => {
|
// app.use('/sendEmail', async (req, res) => {
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in new issue
Block a user