Merge pull request #439 from bluewave-labs/fix/docs

Fix/docs
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-07-24 12:11:09 -07:00
commit ce25ff4fd6
3 files changed
+169 -111

No files matched your search

+160 -110
View File
@@ -302,38 +302,39 @@ Example:
##### Method/Headers ##### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ---------------- | > | -------------- | ------------------- |
> | Method | POST | > | Method | POST |
> | content-type | application/json | > | content-type | multipart/form-data |
##### Body ##### Form
> | Name | Type | Notes | > | Name | Type | Notes |
> | --------- | -------- | ------------------- | > | --------- | --------------- | ----------------------------------------------- |
> | firstname | `string` | | > | firstName | `string` | |
> | lastname | `string` | > | lastName | `string` | |
> | email | `string` | Valid email address | > | email | `string` | Valid email address |
> | password | `string` | Min 8 chars | > | password | `string` | Min 8 chars, One Upper, one number, one special |
> | role | `Array<string>` | Array of user roles |
##### Response Payload ##### Response Payload
> | Type | Notes | > | Type | Notes |
> | ---- | ---------------------------------- | > | ---- | -------------- |
> | JWT | JSON Web Token containing a `User` | > | User | User data |
> | JWT | JSON web token |
##### Sample CURL request ##### Sample CURL request
``` ```
curl --request POST \ curl --request POST \
--url http://localhost:5000/api/v1/auth/register \ --url http://localhost:5000/api/v1/auth/register \
--header 'Content-Type: application/json' \ --header 'Content-Type: multipart/form-data' \
--data '{ --form firstName=Alex \
"firstname" : "User First Name", --form lastName=Hollidaty \
"lastname": "User Last Name", --form email=ajhollid@gmail.com \
"email" : "user@gmail.com", --form 'password=Testtest1!' \
"password": "user_password" --form 'role[]=admin'
}'
``` ```
##### Sample Response ##### Sample Response
@@ -341,8 +342,22 @@ curl --request POST \
```json ```json
{ {
"success": true, "success": true,
"msg": "User created", "msg": "User created successfully",
"data": "<encoded_user>" "data": {
"user": {
"_id": "66a1425b873da2207443f192",
"firstName": "First Name",
"lastName": "Last Name",
"email": "name@gmail.com",
"isActive": true,
"isVerified": false,
"role": ["admin"],
"createdAt": "2024-07-24T18:05:15.852Z",
"updatedAt": "2024-07-24T18:05:15.852Z",
"__v": 0
},
"token": "<token>"
}
} }
``` ```
@@ -363,23 +378,25 @@ curl --request POST \
> | Name | Type | Notes | > | Name | Type | Notes |
> | -------- | -------- | ------------------- | > | -------- | -------- | ------------------- |
> | email | `string` | Valid email address | > | email | `string` | Valid email address |
> | password | `string` | Min 8 chars | > | password | `string` | |
##### Response Payload ##### Response Payload
> | Type | Notes | > | Type | Notes |
> | ---- | ---------------------------------- | > | ---- | -------------- |
> | JWT | JSON Web Token Containing a `User` | > | User | User data |
> | JWT | JSON web token |
##### Sample CURL request ##### Sample CURL request
``` ```
curl --request POST \ curl --request POST \
--url http://localhost:5000/api/v1/auth/login \ --url http://localhost:5000/api/v1/auth/login \
--header 'Authorization: Bearer undefined' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--data '{ --data '{
"email" : "user@gmail.com", "email" : "name@gmail.com",
"password": "user_password" "password": "Testtest1!"
}' }'
``` ```
@@ -387,9 +404,25 @@ curl --request POST \
```json ```json
{ {
"success": true, {
"msg": "Found user", "success": true,
"data": "<encoded_user>" "msg": "User logged in successfully",
"data": {
"user": {
"_id": "66a1425b873da2207443f192",
"firstName": "First Name",
"lastName": "Last Name",
"email": "name@gmail.com",
"isActive": true,
"isVerified": false,
"role": ["admin"],
"createdAt": "2024-07-24T18:05:15.852Z",
"updatedAt": "2024-07-24T18:05:15.852Z",
"__v": 0
},
"token": "<token>"
}
}
} }
``` ```
@@ -400,18 +433,20 @@ curl --request POST \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ------------------- |
> | Method | POST | > | Method | POST |
> | content-type | multipart/form-data |
##### Body ##### Form
> | Name | Type | Notes | > | Name | Type | Notes |
> | ------------- | -------- | ----------- | > | ----------- | -------- | --------------------------- |
> | firstname | `string` | | > | firstName | `string` | Optional |
> | lastname | `string` | | > | lastName | `string` | Optional |
> | profilePicUrl | `string` | | > | profileIame | `file` | Optional |
> | password | `string` | Min 8 chars | > | password | `string` | Required to change password |
> | newPassword | `string` | Required to change password |
###### Response Payload ###### Response Payload
@@ -423,13 +458,14 @@ curl --request POST \
``` ```
curl --request POST \ curl --request POST \
--url http://localhost:5000/api/v1/auth/user/6654d156634754f789e1f10e \ --url http://localhost:5000/api/v1/auth/user/66a1425b873da2207443f192 \
--header 'Authorization: <bearer_token>' \ --header 'Authorization: <bearer_token>' \
--header 'Content-Type: application/json' \ --header 'Content-Type: multipart/form-data' \
--data '{ --form firstName=Test \
"firstname": "First Name", --form lastName=Test \
"lastname: "Last Name" --form profileImage=@/home/user/Desktop/cat.jpg \
}' --form 'newPassword=Testtest1!' \
--form 'password=Testtest2!'
``` ```
###### Sample Response ###### Sample Response
@@ -437,17 +473,19 @@ curl --request POST \
```json ```json
{ {
"success": true, "success": true,
"msg": "User updated", "msg": "User updated successfully",
"data": { "data": {
"_id": "6654d156634754f789e1f10e", "_id": "66a1425b873da2207443f192",
"firstname": "First Name", "firstName": "First name",
"lastname": "Last Name", "lastName": "Last name",
"email": "me@gmail.com", "email": "name@gmail.com",
"isActive": true, "isActive": true,
"isVerified": false, "isVerified": false,
"createdAt": "2024-05-27T18:30:46.358Z", "role": ["admin"],
"updatedAt": "2024-05-27T19:21:51.747Z", "createdAt": "2024-07-24T18:05:15.852Z",
"__v": 0 "updatedAt": "2024-07-24T18:31:32.314Z",
"__v": 0,
"avatarImage": "<Base64 Image>"
} }
} }
``` ```
@@ -459,9 +497,10 @@ curl --request POST \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | GET | > | Method | GET |
> | content-type | application/json |
###### Response Payload ###### Response Payload
@@ -475,7 +514,6 @@ curl --request POST \
curl --request GET \ curl --request GET \
--url http://localhost:5000/api/v1/auth/users \ --url http://localhost:5000/api/v1/auth/users \
--header 'Authorization: <bearer_token>\ --header 'Authorization: <bearer_token>\
--header 'User-Agent: insomnia/2023.5.8'
``` ```
##### Sample Resonse ##### Sample Resonse
@@ -487,9 +525,9 @@ curl --request GET \
"data": [ "data": [
{ {
"_id": "669e90072d5663d25808bc7b", "_id": "669e90072d5663d25808bc7b",
"firstName": "Alex", "firstName": "First name",
"lastName": "Holliday", "lastName": "Last name",
"email": "test@test.com", "email": "name@gmail.com",
"isActive": true, "isActive": true,
"isVerified": false, "isVerified": false,
"role": ["admin"], "role": ["admin"],
@@ -508,9 +546,10 @@ curl --request GET \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | POST | > | Method | POST |
> | content-type | application/json |
##### Body ##### Body
@@ -531,7 +570,7 @@ curl --request POST \
--url http://localhost:5000/api/v1/auth/recovery/request \ --url http://localhost:5000/api/v1/auth/recovery/request \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--data '{ --data '{
"email" : "ajhollid@gmail.com" "email" : "name@gmail.com"
}' }'
``` ```
@@ -542,7 +581,7 @@ curl --request POST \
"success": true, "success": true,
"msg": "Created recovery token", "msg": "Created recovery token",
"data": { "data": {
"email": "your_email@gmail.com", "email": "name@gmail.com",
"token": "f519da5e4a9be40cfc3c0fde97e60c0e6d17bdaa613f5ba537a45073f3865193", "token": "f519da5e4a9be40cfc3c0fde97e60c0e6d17bdaa613f5ba537a45073f3865193",
"_id": "6668878263587f30748e968e", "_id": "6668878263587f30748e968e",
"expiry": "2024-06-11T17:21:06.984Z", "expiry": "2024-06-11T17:21:06.984Z",
@@ -560,9 +599,10 @@ curl --request POST \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | POST | > | Method | POST |
> | content-type | application/json |
##### Body ##### Body
@@ -595,7 +635,7 @@ curl --request POST \
"msg": "Token is valid", "msg": "Token is valid",
"data": { "data": {
"_id": "6668894263587f30748e969a", "_id": "6668894263587f30748e969a",
"email": "ajhollid@gmail.com", "email": "name@gmail.com",
"token": "457d9926b24dedf613f120eeb524ef00ac45b3f0fc5c70bd25b1cc8aa83a64a0", "token": "457d9926b24dedf613f120eeb524ef00ac45b3f0fc5c70bd25b1cc8aa83a64a0",
"expiry": "2024-06-11T17:28:34.349Z", "expiry": "2024-06-11T17:28:34.349Z",
"createdAt": "2024-06-11T17:28:34.349Z", "createdAt": "2024-06-11T17:28:34.349Z",
@@ -612,9 +652,10 @@ curl --request POST \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | POST | > | Method | POST |
> | content-type | application/json |
##### Body ##### Body
@@ -649,9 +690,9 @@ curl --request POST \
"msg": "Password reset", "msg": "Password reset",
"data": { "data": {
"_id": "66675891cb17336d84c25d9f", "_id": "66675891cb17336d84c25d9f",
"firstname": "User First Name", "firstname": "First Name",
"lastname": "User Last Name", "lastname": "Last Name",
"email": "your_email@gmail.com", "email": "name@gmail.com",
"isActive": true, "isActive": true,
"isVerified": false, "isVerified": false,
"createdAt": "2024-06-10T19:48:33.863Z", "createdAt": "2024-06-10T19:48:33.863Z",
@@ -672,9 +713,10 @@ curl --request POST \
##### Method/Headers ##### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | GET | > | Method | GET |
> | content-type | application/json |
##### Response Payload ##### Response Payload
@@ -732,9 +774,10 @@ curl --request GET \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | GET | > | Method | GET |
> | content-type | application/json |
###### Response Payload ###### Response Payload
@@ -803,9 +846,10 @@ curl --request GET \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | GET | > | Method | GET |
> | content-type | application/json |
###### Response Payload ###### Response Payload
@@ -865,21 +909,22 @@ curl --request GET \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | POST | > | Method | POST |
> | content-type | application/json |
##### Body ##### Body
> | Name | Type | Notes | Accepted Values | > | Name | Type | Notes | Accepted Values |
> | ----------- | --------- | ---------------------- | ---------------------- | > | ----------- | --------- | ---------------------- | --------------------------------------- |
> | userId | `string` | UserId of current user | | > | userId | `string` | UserId of current user | |
> | name | `string` | Monitor name | | > | name | `string` | Monitor name | |
> | description | `string` | Monitor Description | | > | description | `string` | Monitor Description | |
> | type | `string` | Valid email address | `"ping"`&#124;`"http"` | > | type | `string` | Valid email address | `"ping"`&#124;`"http"`&#124;`pagespeed` |
> | url | `string` | URL of service or IP | | > | url | `string` | URL of service or IP | |
> | isActive | `boolean` | | | > | isActive | `boolean` | | |
> | interval | `number` | In ms | | > | interval | `number` | In ms | |
###### Response Payload ###### Response Payload
@@ -894,7 +939,6 @@ curl --request POST \
--url http://localhost:5000/api/v1/monitors \ --url http://localhost:5000/api/v1/monitors \
--header <bearer_token> \ --header <bearer_token> \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/2023.5.8' \
--data '{ --data '{
"userId": "66675891cb17336d84c25d9f", "userId": "66675891cb17336d84c25d9f",
"name": "Ping Google", "name": "Ping Google",
@@ -933,9 +977,10 @@ curl --request POST \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | POST | > | Method | POST |
> | content-type | application/json |
###### Response Payload ###### Response Payload
@@ -968,9 +1013,18 @@ curl --request POST \
###### Method/Headers ###### Method/Headers
> | Method/Headers | Value | > | Method/Headers | Value |
> | -------------- | ----- | > | -------------- | ---------------- |
> | Method | POST | > | Method | POST |
> | content-type | application/json |
##### Body
> | Name | Type | Notes | Accepted Values |
> | ----------- | -------- | ------------------- | --------------- |
> | name | `string` | Monitor name | |
> | description | `string` | Monitor Description | |
> | interval | `number` | In ms |
###### Response Payload ###### Response Payload
@@ -987,12 +1041,8 @@ curl --request POST \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--data ' --data '
{ {
"_id": "664e5ccf189c864800debc16",
"userId": "6645079aae0b439371913972",
"name": "Edited monitor", "name": "Edited monitor",
"description": "Description", "description": "Description",
"url": "https://monitor0.com",
"isActive": true,
"interval": 60000 "interval": 60000
}' }'
``` ```
+2 -1
View File
@@ -2,6 +2,7 @@ const {
getMonitorByIdValidation, getMonitorByIdValidation,
getMonitorsByUserIdValidation, getMonitorsByUserIdValidation,
monitorValidation, monitorValidation,
editMonitorBodyValidation,
} = require("../validation/joi"); } = require("../validation/joi");
const SERVICE_NAME = "monitorController"; const SERVICE_NAME = "monitorController";
@@ -251,7 +252,7 @@ const deleteAllMonitors = async (req, res) => {
const editMonitor = async (req, res, next) => { const editMonitor = async (req, res, next) => {
try { try {
await getMonitorByIdValidation.validateAsync(req.params); await getMonitorByIdValidation.validateAsync(req.params);
await monitorValidation.validateAsync(req.body); await editMonitorBodyValidation.validateAsync(req.body);
} catch (error) { } catch (error) {
error.status = 422; error.status = 422;
error.service = SERVICE_NAME; error.service = SERVICE_NAME;
+7
View File
@@ -137,6 +137,12 @@ const monitorValidation = joi.object({
interval: joi.number(), interval: joi.number(),
}); });
const editMonitorBodyValidation = joi.object({
name: joi.string(),
description: joi.string(),
interval: joi.number(),
});
//**************************************** //****************************************
// Alerts // Alerts
//**************************************** //****************************************
@@ -245,6 +251,7 @@ module.exports = {
getMonitorByIdValidation, getMonitorByIdValidation,
getMonitorsByUserIdValidation, getMonitorsByUserIdValidation,
monitorValidation, monitorValidation,
editMonitorBodyValidation,
editUserParamValidation, editUserParamValidation,
editUserBodyValidation, editUserBodyValidation,
createAlertParamValidation, createAlertParamValidation,