Open TracyChacon opened 1 year ago
Chapter: 11 Admin Screens -Part 1
Video: Getting a User by ID and Updating User Endpoints
TimeStamp: 07:25
userController.js
`updateUser
When testing the backend using postman with the codeuser.isAdmin = req.body.isAdmin in userConroller.js the below error error appears
user.isAdmin = req.body.isAdmin
userConroller.js
Error: "message": "User validation failed: isAdmin: Path isAdmin is required.", "stack": "ValidationError: User validation failed: isAdmin: Path isAdmin is required.\n at model.Document.invalidate
isAdmin
The following code in the body section of postman causes the the error
{ "name": "jane dolittle" }
An ad hoc fix is including the isAdmin value. The below code allows the tester to update user values.
{ "name": "jane dolittle", "isAdmin": false }
The proposed code change makes it so that you don't need to include the isAdmin value in the JSON to fix the issue.
Change, in updateUser() function, line 153 from :
updateUser()
To:
user.isAdmin = Object.is(req.body.isAdmin, undefined) ? user.isAdmin : req.body.isAdmin
DETAILS
Chapter: 11 Admin Screens -Part 1
Video: Getting a User by ID and Updating User Endpoints
TimeStamp: 07:25
userController.js
file, line 153, inside the`updateUser
function.ISSUE
When testing the backend using postman with the code
user.isAdmin = req.body.isAdmin
inuserConroller.js
the below error error appearsError: "message": "User validation failed: isAdmin: Path
isAdmin
is required.", "stack": "ValidationError: User validation failed: isAdmin: PathisAdmin
is required.\n at model.Document.invalidateUSECASE
The following code in the body section of postman causes the the error
TEMP FIX
An ad hoc fix is including the
isAdmin
value. The below code allows the tester to update user values.PROPOSED CHANGE
The proposed code change makes it so that you don't need to include the
isAdmin
value in the JSON to fix the issue.Change, in
updateUser()
function, line 153 from :To: