Skip to content

Conversation

@HuangBohan
Copy link

No description provided.

Copy link
Member

@Gisonrg Gisonrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update according to comments.
Noted that don't wait for DB error to conclude that inputs are invalid.

exports.updateUserSpritename = function(req, res) {
var query = { '_id': req.user._id };
if (!req.body.spritename) {
res.send({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a return here
Add a status code (400)

error: "Please input new spritename for update"
});
}
var updateAttributes = { "spritename":req.body.spritename }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check not empty and limit the input length?

updateAttributes['healthLimit'] = req.body.healthLimit
}
if (!updateAttributes.strength && !updateAttributes.stamina && !updateAttributes.agility && !updateAttributes.health && !updateAttributes.healthLimit) {
res.send({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return, status code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condition should be || (reject as long as one input is not correct)
Also, specify the condition explicitly (for example, must be >= 0)

exports.updateUserSkills = function(req, res) {
var query = { '_id': req.user._id };
if (!req.body.skills) {
res.send({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return and status code, same for all codes below

if (req.body.experience) {
updateAttributes['experience'] = req.body.experience
}
if (!updateAttributes.level && !updateAttributes.experience) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. condition should be || (no level or no experience)
  2. if level == 0, !level will be true. Write explicit condition

// Get user
router.get('/users/:id', verifyToken, authCtrl.refreshToken, userCtrl.getUser);
// Update user
router.post('/users', verifyToken, authCtrl.refreshToken, userCtrl.updateUser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept this method and its route for now. Not all users will upgrade to use Api v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants