-
Notifications
You must be signed in to change notification settings - Fork 0
Staging #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Staging #2
Changes from all commits
e9202b4
3e01eea
69ce752
84fa4c9
2dccb6d
3fc2ba9
e9b9bb3
318c0cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ exports.getUser = function(req, res) { | |
| { | ||
| 'facebookId': req.params.id | ||
| }, | ||
| '_id username facebookId level health health_limit agility appearance strength spritename stamina skillInUse', | ||
| '_id username facebookId level health agility appearance strength spritename stamina skillInUse experience healthLimit', | ||
| function(err, user) { | ||
| if (err) { | ||
| return res.status(500).json({ | ||
|
|
@@ -28,18 +28,133 @@ exports.getUser = function(req, res) { | |
| }); | ||
| }; | ||
|
|
||
| exports.updateUser = function(req, res) { | ||
| var query = { '_id': req.user._id }; | ||
| User.findOneAndUpdate(query, req.body.newData, { upsert:true }, function(err, user) { | ||
| if (err) { | ||
| return res.status(500).json({ | ||
| message: err.message | ||
| }) | ||
| } | ||
| res.send({ | ||
| status: "ok", | ||
| }); | ||
| }); | ||
| exports.updateUserSpritename = function(req, res) { | ||
| var query = { '_id': req.user._id }; | ||
| if (!req.body.spritename) { | ||
| res.send({ | ||
| status: "error", | ||
| error: "Please input new spritename for update" | ||
| }); | ||
| } | ||
| var updateAttributes = { "spritename":req.body.spritename } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check not empty and limit the input length? |
||
| User.findOneAndUpdate(query, updateAttributes, { upsert:true }, function(err, user) { | ||
| if (err) { | ||
| return res.status(500).json({ | ||
| message: err.message | ||
| }) | ||
| } | ||
| res.send({ | ||
| status: "ok", | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| //(strength, stamina, agility, health, healthLimit) | ||
| exports.updateUserAttributes = function(req, res) { | ||
| var query = { '_id': req.user._id }; | ||
| var updateAttributes = {} | ||
| if (req.body.strength) { | ||
| updateAttributes['strength'] = req.body.strength | ||
| } | ||
| if (req.body.stamina) { | ||
| updateAttributes['stamina'] = req.body.stamina | ||
| } | ||
| if (req.body.agility) { | ||
| updateAttributes['agility'] = req.body.agility | ||
| } | ||
| if (req.body.health) { | ||
| updateAttributes['health'] = req.body.health | ||
| } | ||
| if (req.body.healthLimit) { | ||
| updateAttributes['healthLimit'] = req.body.healthLimit | ||
| } | ||
| if (!updateAttributes.strength && !updateAttributes.stamina && !updateAttributes.agility && !updateAttributes.health && !updateAttributes.healthLimit) { | ||
| res.send({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. condition should be |
||
| status: "error", | ||
| error: "Please input attributes for update" | ||
| }); | ||
| } | ||
|
|
||
| User.findOneAndUpdate(query, updateAttributes, { upsert:true }, function(err, user) { | ||
| if (err) { | ||
| return res.status(500).json({ | ||
| message: err.message | ||
| }) | ||
| } | ||
| res.send({ | ||
| status: "ok", | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| exports.updateUserSkills = function(req, res) { | ||
| var query = { '_id': req.user._id }; | ||
| if (!req.body.skills) { | ||
| res.send({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| status: "error", | ||
| error: "Please input skills in used for update" | ||
| }); | ||
| } | ||
| var updateAttributes = { "skillInUse":req.body.skills } | ||
| User.findOneAndUpdate(query, updateAttributes, { upsert:true }, function(err, user) { | ||
| if (err) { | ||
| return res.status(500).json({ | ||
| message: err.message | ||
| }) | ||
| } | ||
| res.send({ | ||
| status: "ok", | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| exports.updateUserAppearance = function(req, res) { | ||
| var query = { '_id': req.user._id }; | ||
| if (!req.body.appearance) { | ||
| res.send({ | ||
| status: "error", | ||
| error: "Please input appearance for update" | ||
| }); | ||
| } | ||
| var updateAttributes = { "appearance":req.body.appearance } | ||
| User.findOneAndUpdate(query, updateAttributes, { upsert:true }, function(err, user) { | ||
| if (err) { | ||
| return res.status(500).json({ | ||
| message: err.message | ||
| }) | ||
| } | ||
| res.send({ | ||
| status: "ok", | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| exports.updateUserLevelExperience = function(req, res) { | ||
| var query = { '_id': req.user._id }; | ||
| var updateAttributes = {} | ||
| if (req.body.level) { | ||
| updateAttributes['level'] = req.body.level | ||
| } | ||
| if (req.body.experience) { | ||
| updateAttributes['experience'] = req.body.experience | ||
| } | ||
| if (!updateAttributes.level && !updateAttributes.experience) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| res.send({ | ||
| status: "error", | ||
| error: "Please input level / experience for update" | ||
| }); | ||
| } | ||
|
|
||
| User.findOneAndUpdate(query, updateAttributes, { upsert:true }, function(err, user) { | ||
| if (err) { | ||
| return res.status(500).json({ | ||
| message: err.message | ||
| }) | ||
| } | ||
| res.send({ | ||
| status: "ok", | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| exports.getFriends = function(req, res) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,15 +28,19 @@ router.get('/me', verifyToken, authCtrl.refreshToken, function(req, res) { | |
| router.get('/users/friends', verifyToken, authCtrl.refreshToken, userCtrl.getFriends); | ||
| // Get user | ||
| router.get('/users/:id', verifyToken, authCtrl.refreshToken, userCtrl.getUser); | ||
| // Update user | ||
| router.post('/users', verifyToken, authCtrl.refreshToken, userCtrl.updateUser); | ||
| // Update user spritename | ||
| router.post('/users/spritename', verifyToken, authCtrl.refreshToken, userCtrl.updateUserSpritename); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| // Update user mi attributes (strength, stamina, agility, health, healthLimit) | ||
| router.post('/users/attributes', verifyToken, authCtrl.refreshToken, userCtrl.updateUserAttributes); | ||
| // Update user skills is used in use | ||
| router.post('/users/skills', verifyToken, authCtrl.refreshToken, userCtrl.updateUserSkills); | ||
| // Update user appearance | ||
| router.post('/users/appearance', verifyToken, authCtrl.refreshToken, userCtrl.updateUserAppearance); | ||
| // Update user level and experience | ||
| router.post('/users/level_experience', verifyToken, authCtrl.refreshToken, userCtrl.updateUserLevelExperience); | ||
| // Add combat | ||
| router.post('/combats/create', verifyToken, authCtrl.refreshToken, combatCtrl.createCombat); | ||
| // Get combat | ||
| router.get('/combats/:id', verifyToken, authCtrl.refreshToken, combatCtrl.getCombat); | ||
| // Add combat | ||
| router.post('/skills/create', verifyToken, authCtrl.refreshToken, skillCtrl.createSkill); | ||
| // Add combat | ||
| router.get('/skills/:id', verifyToken, authCtrl.refreshToken, skillCtrl.getSkill); | ||
|
|
||
| module.exports = router; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a
returnhereAdd a status code (400)