mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
v3 adapt v2: fix a few bugs with batchUpdate and tasks
This commit is contained in:
@@ -820,6 +820,7 @@ api.deleteTask = function(req, res, next) {
|
||||
|
||||
api.updateTask = function(req, res, next) {
|
||||
var user = res.locals.user;
|
||||
req.body = Tasks.Task.fromJSONV2(req.body);
|
||||
|
||||
Tasks.Task.findOne({
|
||||
_id: req.params.id,
|
||||
@@ -845,6 +846,7 @@ api.addTask = function(req, res, next) {
|
||||
var user = res.locals.user;
|
||||
req.body.type = req.body.type || 'habit';
|
||||
req.body.text = req.body.text || 'text';
|
||||
req.body = Tasks.Task.fromJSONV2(req.body);
|
||||
|
||||
var task = new Tasks[req.body.type](Tasks.Task.sanitizeCreate(req.body));
|
||||
|
||||
@@ -920,8 +922,8 @@ api.batchUpdate = function(req, res, next) {
|
||||
var oldJson = res.json;
|
||||
|
||||
// Stash user.save, we'll queue the save op till the end (so we don't overload the server)
|
||||
var oldSave = user.save;
|
||||
user.save = function(cb){cb(null,user)}
|
||||
//var oldSave = user.save;
|
||||
//user.save = function(cb){cb(null,user)}
|
||||
|
||||
// Setup the array of functions we're going to call in parallel with async
|
||||
res.locals.ops = [];
|
||||
@@ -943,13 +945,13 @@ api.batchUpdate = function(req, res, next) {
|
||||
});
|
||||
})
|
||||
// Finally, save user at the end
|
||||
.concat(function(){
|
||||
.concat(/*function(){
|
||||
user.save = oldSave;
|
||||
user.save(arguments[arguments.length-1]);
|
||||
});
|
||||
}*/);
|
||||
|
||||
// call all the operations, then return the user object to the requester
|
||||
asyncM.waterfall(ops, function(err,_user) {
|
||||
asyncM.waterfall(ops, function(err) {
|
||||
res.json = oldJson;
|
||||
res.send = oldSend;
|
||||
if (err) return next(err);
|
||||
@@ -957,14 +959,14 @@ api.batchUpdate = function(req, res, next) {
|
||||
var response;
|
||||
|
||||
// return only drops & streaks
|
||||
if (_user._tmp && _user._tmp.drop){
|
||||
response = _user.toJSON();
|
||||
if (user._tmp && user._tmp.drop){
|
||||
response = user.toJSON();
|
||||
res.status(200).json({_tmp: {drop: response._tmp.drop}, _v: response._v});
|
||||
|
||||
// Fetch full user object
|
||||
} else if (res.locals.wasModified){
|
||||
// Preen 3-day past-completed To-Dos from Angular & mobile app
|
||||
_user.getTransformedData(function(err, transformedData){
|
||||
user.getTransformedData(function(err, transformedData){
|
||||
if (err) next(err);
|
||||
response = transformedData;
|
||||
|
||||
@@ -973,12 +975,12 @@ api.batchUpdate = function(req, res, next) {
|
||||
});
|
||||
// return only the version number
|
||||
} else{
|
||||
response = _user.toJSON();
|
||||
response = user.toJSON();
|
||||
res.status(200).json({_v: response._v});
|
||||
}
|
||||
|
||||
user.fns.nullify();
|
||||
user = res.locals.user = oldSend = oldJson = oldSave = null;
|
||||
//user.fns.nullify();
|
||||
user = res.locals.user = oldSend = oldJson = null;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user