diff --git a/README.md b/README.md index 753aeb2af..5e0ade008 100644 --- a/README.md +++ b/README.md @@ -497,9 +497,10 @@ curl --request POST \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | GET | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | GET | +> | content-type | application/json | ###### Response Payload @@ -545,9 +546,10 @@ curl --request GET \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | POST | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | POST | +> | content-type | application/json | ##### Body @@ -568,7 +570,7 @@ curl --request POST \ --url http://localhost:5000/api/v1/auth/recovery/request \ --header 'Content-Type: application/json' \ --data '{ - "email" : "ajhollid@gmail.com" + "email" : "name@gmail.com" }' ``` @@ -579,7 +581,7 @@ curl --request POST \ "success": true, "msg": "Created recovery token", "data": { - "email": "your_email@gmail.com", + "email": "name@gmail.com", "token": "f519da5e4a9be40cfc3c0fde97e60c0e6d17bdaa613f5ba537a45073f3865193", "_id": "6668878263587f30748e968e", "expiry": "2024-06-11T17:21:06.984Z", @@ -597,9 +599,10 @@ curl --request POST \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | POST | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | POST | +> | content-type | application/json | ##### Body @@ -632,7 +635,7 @@ curl --request POST \ "msg": "Token is valid", "data": { "_id": "6668894263587f30748e969a", - "email": "ajhollid@gmail.com", + "email": "name@gmail.com", "token": "457d9926b24dedf613f120eeb524ef00ac45b3f0fc5c70bd25b1cc8aa83a64a0", "expiry": "2024-06-11T17:28:34.349Z", "createdAt": "2024-06-11T17:28:34.349Z", @@ -649,9 +652,10 @@ curl --request POST \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | POST | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | POST | +> | content-type | application/json | ##### Body @@ -686,9 +690,9 @@ curl --request POST \ "msg": "Password reset", "data": { "_id": "66675891cb17336d84c25d9f", - "firstname": "User First Name", - "lastname": "User Last Name", - "email": "your_email@gmail.com", + "firstname": "First Name", + "lastname": "Last Name", + "email": "name@gmail.com", "isActive": true, "isVerified": false, "createdAt": "2024-06-10T19:48:33.863Z", @@ -709,9 +713,10 @@ curl --request POST \ ##### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | GET | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | GET | +> | content-type | application/json | ##### Response Payload @@ -769,9 +774,10 @@ curl --request GET \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | GET | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | GET | +> | content-type | application/json | ###### Response Payload @@ -840,9 +846,10 @@ curl --request GET \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | GET | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | GET | +> | content-type | application/json | ###### Response Payload @@ -902,21 +909,22 @@ curl --request GET \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | POST | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | POST | +> | content-type | application/json | ##### Body -> | Name | Type | Notes | Accepted Values | -> | ----------- | --------- | ---------------------- | ---------------------- | -> | userId | `string` | UserId of current user | | -> | name | `string` | Monitor name | | -> | description | `string` | Monitor Description | | -> | type | `string` | Valid email address | `"ping"`|`"http"` | -> | url | `string` | URL of service or IP | | -> | isActive | `boolean` | | | -> | interval | `number` | In ms | | +> | Name | Type | Notes | Accepted Values | +> | ----------- | --------- | ---------------------- | --------------------------------------- | +> | userId | `string` | UserId of current user | | +> | name | `string` | Monitor name | | +> | description | `string` | Monitor Description | | +> | type | `string` | Valid email address | `"ping"`|`"http"`|`pagespeed` | +> | url | `string` | URL of service or IP | | +> | isActive | `boolean` | | | +> | interval | `number` | In ms | | ###### Response Payload @@ -931,7 +939,6 @@ curl --request POST \ --url http://localhost:5000/api/v1/monitors \ --header \ --header 'Content-Type: application/json' \ - --header 'User-Agent: insomnia/2023.5.8' \ --data '{ "userId": "66675891cb17336d84c25d9f", "name": "Ping Google", @@ -970,9 +977,10 @@ curl --request POST \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | POST | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | Method | POST | +> | content-type | application/json | ###### Response Payload @@ -1005,9 +1013,18 @@ curl --request POST \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | POST | +> | Method/Headers | Value | +> | -------------- | ---------------- | +> | 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 @@ -1024,12 +1041,8 @@ curl --request POST \ --header 'Content-Type: application/json' \ --data ' { - "_id": "664e5ccf189c864800debc16", - "userId": "6645079aae0b439371913972", "name": "Edited monitor", "description": "Description", - "url": "https://monitor0.com", - "isActive": true, "interval": 60000 }' ``` diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 45a55a973..1e3f3db4e 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -2,6 +2,7 @@ const { getMonitorByIdValidation, getMonitorsByUserIdValidation, monitorValidation, + editMonitorBodyValidation, } = require("../validation/joi"); const SERVICE_NAME = "monitorController"; @@ -251,7 +252,7 @@ const deleteAllMonitors = async (req, res) => { const editMonitor = async (req, res, next) => { try { await getMonitorByIdValidation.validateAsync(req.params); - await monitorValidation.validateAsync(req.body); + await editMonitorBodyValidation.validateAsync(req.body); } catch (error) { error.status = 422; error.service = SERVICE_NAME; diff --git a/Server/validation/joi.js b/Server/validation/joi.js index 6384f13ba..98c3e3835 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -137,6 +137,12 @@ const monitorValidation = joi.object({ interval: joi.number(), }); +const editMonitorBodyValidation = joi.object({ + name: joi.string(), + description: joi.string(), + interval: joi.number(), +}); + //**************************************** // Alerts //**************************************** @@ -245,6 +251,7 @@ module.exports = { getMonitorByIdValidation, getMonitorsByUserIdValidation, monitorValidation, + editMonitorBodyValidation, editUserParamValidation, editUserBodyValidation, createAlertParamValidation,