bradtraversy / proshop_mern

Shopping cart built with MERN & Redux
1.99k stars 1.18k forks source link

FIX - postman testing issue gives error if {"admin": false} is not included in json body #214

Open TracyChacon opened 1 year ago

TracyChacon commented 1 year ago

DETAILS

USECASE

The following code in the body section of postman causes the the error

{ 
"name":  "jane dolittle"
}

TEMP FIX

An ad hoc fix is including the isAdmin value. The below code allows the tester to update user values.

{ 
"name":  "jane dolittle",
"isAdmin": false 
}

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 :


user.isAdmin = req.body.isAdmin

To:

user.isAdmin = Object.is(req.body.isAdmin, undefined)
      ? user.isAdmin
      : req.body.isAdmin