mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-18 01:42:20 +00:00
Clean up groups controller
* Put nullifying variables back in per https://github.com/HabitRPG/habitrpg/pull/5437/files#r32896108 * converted questStart to a hoisted function
This commit is contained in:
parent
c6256d7fa1
commit
54509d234c
1 changed files with 10 additions and 4 deletions
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
// @see ../routes for routing
|
||||
|
||||
function clone(a) {
|
||||
|
|
@ -195,7 +196,7 @@ api.create = function(req, res, next) {
|
|||
group = user = null;
|
||||
});
|
||||
|
||||
}else{
|
||||
} else{
|
||||
async.waterfall([
|
||||
function(cb){
|
||||
Group.findOne({type:'party',members:{$in:[user._id]}},cb);
|
||||
|
|
@ -210,6 +211,7 @@ api.create = function(req, res, next) {
|
|||
], function(err, populated){
|
||||
if (err == 'Already in a party, try refreshing.') return res.json(400,{err:err});
|
||||
if (err) return next(err);
|
||||
group = user = null;
|
||||
return res.json(populated);
|
||||
})
|
||||
}
|
||||
|
|
@ -284,7 +286,8 @@ api.postChat = function(req, res, next) {
|
|||
|
||||
group.save(function(err, saved){
|
||||
if (err) return next(err);
|
||||
return chatUpdated ? res.json({chat: group.chat}) : res.json({message: saved.chat[0]});
|
||||
chatUpdated ? res.json({chat: group.chat}) : res.json({message: saved.chat[0]});
|
||||
group = chatUpdated = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -304,7 +307,8 @@ api.deleteChatMessage = function(req, res, next){
|
|||
|
||||
Group.update({_id:group._id}, {$pull:{chat:{id: req.params.messageId}}}, function(err){
|
||||
if(err) return next(err);
|
||||
return chatUpdated ? res.json({chat: group.chat}) : res.send(204);
|
||||
chatUpdated ? res.json({chat: group.chat}) : res.send(204);
|
||||
group = chatUpdated = null;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -546,6 +550,7 @@ api.leave = function(req, res, next) {
|
|||
}
|
||||
],function(err){
|
||||
if (err) return next(err);
|
||||
user = group = keep = null;
|
||||
return res.send(204);
|
||||
})
|
||||
}
|
||||
|
|
@ -782,6 +787,7 @@ api.removeMember = function(req, res, next){
|
|||
|
||||
});
|
||||
}else{
|
||||
group = uuid = null;
|
||||
return res.json(400, {err: "User not found among group's members!"});
|
||||
}
|
||||
}
|
||||
|
|
@ -790,7 +796,7 @@ api.removeMember = function(req, res, next){
|
|||
// Quests
|
||||
// ------------------------------------
|
||||
|
||||
questStart = function(req, res, next) {
|
||||
function questStart(req, res, next) {
|
||||
var group = res.locals.group;
|
||||
var force = req.query.force;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue