From 708c4838769f56d29717d1fafe11b9b496ff6228 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 24 Jul 2024 11:06:06 -0700 Subject: [PATCH 1/5] updated register docs --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index eae2d9e8c..8f634676f 100644 --- a/README.md +++ b/README.md @@ -302,19 +302,20 @@ Example: ##### Method/Headers -> | Method/Headers | Value | -> | -------------- | ---------------- | -> | Method | POST | -> | content-type | application/json | +> | Method/Headers | Value | +> | -------------- | ------------------- | +> | Method | POST | +> | content-type | multipart/form-data | -##### Body +##### Form -> | Name | Type | Notes | -> | --------- | -------- | ------------------- | -> | firstname | `string` | | -> | lastname | `string` | -> | email | `string` | Valid email address | -> | password | `string` | Min 8 chars | +> | Name | Type | Notes | +> | --------- | --------------- | ----------------------------------------------- | +> | firstName | `string` | | +> | lastName | `string` | | +> | email | `string` | Valid email address | +> | password | `string` | Min 8 chars, One Upper, one number, one special | +> | role | `Array` | Array of user roles | ##### Response Payload From b39e80b9dadc0607de3001f73b1fac0628867a6c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 24 Jul 2024 11:11:41 -0700 Subject: [PATCH 2/5] Updated login docs --- README.md | 74 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8f634676f..e63665bae 100644 --- a/README.md +++ b/README.md @@ -319,22 +319,22 @@ Example: ##### Response Payload -> | Type | Notes | -> | ---- | ---------------------------------- | -> | JWT | JSON Web Token containing a `User` | +> | Type | Notes | +> | ---- | -------------- | +> | User | User data | +> | JWT | JSON web token | ##### Sample CURL request ``` curl --request POST \ --url http://localhost:5000/api/v1/auth/register \ - --header 'Content-Type: application/json' \ - --data '{ - "firstname" : "User First Name", - "lastname": "User Last Name", - "email" : "user@gmail.com", - "password": "user_password" -}' + --header 'Content-Type: multipart/form-data' \ + --form firstName=Alex \ + --form lastName=Hollidaty \ + --form email=ajhollid@gmail.com \ + --form 'password=Testtest1!' \ + --form 'role[]=admin' ``` ##### Sample Response @@ -342,8 +342,22 @@ curl --request POST \ ```json { "success": true, - "msg": "User created", - "data": "" + "msg": "User created 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": "" + } } ``` @@ -364,23 +378,25 @@ curl --request POST \ > | Name | Type | Notes | > | -------- | -------- | ------------------- | > | email | `string` | Valid email address | -> | password | `string` | Min 8 chars | +> | password | `string` | | ##### Response Payload -> | Type | Notes | -> | ---- | ---------------------------------- | -> | JWT | JSON Web Token Containing a `User` | +> | Type | Notes | +> | ---- | -------------- | +> | User | User data | +> | JWT | JSON web token | ##### Sample CURL request ``` curl --request POST \ --url http://localhost:5000/api/v1/auth/login \ + --header 'Authorization: Bearer undefined' \ --header 'Content-Type: application/json' \ --data '{ - "email" : "user@gmail.com", - "password": "user_password" + "email" : "name@gmail.com", + "password": "Testtest1!" }' ``` @@ -388,9 +404,25 @@ curl --request POST \ ```json { - "success": true, - "msg": "Found user", - "data": "" +{ + "success": true, + "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": "" + } +} } ``` From 6db9a2f960eae65b9fa160e5c6baac723211371d Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 24 Jul 2024 11:33:20 -0700 Subject: [PATCH 3/5] Update edit user endpoint --- README.md | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index e63665bae..a840d1d5c 100644 --- a/README.md +++ b/README.md @@ -433,18 +433,20 @@ curl --request POST \ ###### Method/Headers -> | Method/Headers | Value | -> | -------------- | ----- | -> | Method | POST | +> | Method/Headers | Value | +> | -------------- | ------------------- | +> | Method | POST | +> | content-type | multipart/form-data | -##### Body +##### Form -> | Name | Type | Notes | -> | ------------- | -------- | ----------- | -> | firstname | `string` | | -> | lastname | `string` | | -> | profilePicUrl | `string` | | -> | password | `string` | Min 8 chars | +> | Name | Type | Notes | +> | ----------- | -------- | --------------------------- | +> | firstName | `string` | Optional | +> | lastName | `string` | Optional | +> | profileIame | `file` | Optional | +> | password | `string` | Required to change password | +> | newPassword | `string` | Required to change password | ###### Response Payload @@ -456,13 +458,14 @@ 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: ' \ - --header 'Content-Type: application/json' \ - --data '{ - "firstname": "First Name", - "lastname: "Last Name" -}' + --header 'Content-Type: multipart/form-data' \ + --form firstName=Test \ + --form lastName=Test \ + --form profileImage=@/home/user/Desktop/cat.jpg \ + --form 'newPassword=Testtest1!' \ + --form 'password=Testtest2!' ``` ###### Sample Response @@ -470,17 +473,19 @@ curl --request POST \ ```json { "success": true, - "msg": "User updated", + "msg": "User updated successfully", "data": { - "_id": "6654d156634754f789e1f10e", - "firstname": "First Name", - "lastname": "Last Name", - "email": "me@gmail.com", + "_id": "66a1425b873da2207443f192", + "firstName": "First name", + "lastName": "Last name", + "email": "name@gmail.com", "isActive": true, "isVerified": false, - "createdAt": "2024-05-27T18:30:46.358Z", - "updatedAt": "2024-05-27T19:21:51.747Z", - "__v": 0 + "role": ["admin"], + "createdAt": "2024-07-24T18:05:15.852Z", + "updatedAt": "2024-07-24T18:31:32.314Z", + "__v": 0, + "avatarImage": "" } } ``` From 3f65973f0c6a51a2d32e6deea01571434b38a337 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 24 Jul 2024 11:34:14 -0700 Subject: [PATCH 4/5] Update get users endpoint --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a840d1d5c..753aeb2af 100644 --- a/README.md +++ b/README.md @@ -513,7 +513,6 @@ curl --request POST \ curl --request GET \ --url http://localhost:5000/api/v1/auth/users \ --header 'Authorization: \ - --header 'User-Agent: insomnia/2023.5.8' ``` ##### Sample Resonse @@ -525,9 +524,9 @@ curl --request GET \ "data": [ { "_id": "669e90072d5663d25808bc7b", - "firstName": "Alex", - "lastName": "Holliday", - "email": "test@test.com", + "firstName": "First name", + "lastName": "Last name", + "email": "name@gmail.com", "isActive": true, "isVerified": false, "role": ["admin"], From d774f36b22972afe6da4c2b35bf999148b86a759 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 24 Jul 2024 12:08:42 -0700 Subject: [PATCH 5/5] Updated validatio nand edit monitor --- README.md | 113 +++++++++++++----------- Server/controllers/monitorController.js | 3 +- Server/validation/joi.js | 7 ++ 3 files changed, 72 insertions(+), 51 deletions(-) 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,