mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
fix: check for _legacyId in tasks if id does not exist
This commit is contained in:
@@ -90,7 +90,6 @@ api.score = function(req, res, next) {
|
|||||||
direction = req.params.direction,
|
direction = req.params.direction,
|
||||||
user = res.locals.user,
|
user = res.locals.user,
|
||||||
body = req.body || {},
|
body = req.body || {},
|
||||||
taskQuery = { userId: user._id },
|
|
||||||
task;
|
task;
|
||||||
|
|
||||||
// Send error responses for improper API call
|
// Send error responses for improper API call
|
||||||
@@ -100,14 +99,23 @@ api.score = function(req, res, next) {
|
|||||||
return res.json(400, {err: ":direction must be 'up' or 'down'"});
|
return res.json(400, {err: ":direction must be 'up' or 'down'"});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validator.isUUID(id)) {
|
asyncM.waterfall([
|
||||||
taskQuery._id = id;
|
function (cb) {
|
||||||
} else {
|
Tasks.Task.findOne({
|
||||||
taskQuery._legacyId = id;
|
_id: id,
|
||||||
}
|
userId: user._id,
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
function (task, cb) {
|
||||||
|
if (task) return cb(null, task);
|
||||||
|
|
||||||
Tasks.Task.findOne(taskQuery, function(err, task){
|
Tasks.Task.findOne({
|
||||||
if(err) return next(err);
|
_legacyId: id,
|
||||||
|
userId: user._id,
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
], function (err, task) {
|
||||||
|
if (err) return next(err);
|
||||||
|
|
||||||
// If exists already, score it
|
// If exists already, score it
|
||||||
if (!task) {
|
if (!task) {
|
||||||
@@ -199,7 +207,6 @@ api.score = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,16 +226,24 @@ api.getTasks = function(req, res, next) {
|
|||||||
*/
|
*/
|
||||||
api.getTask = function(req, res, next) {
|
api.getTask = function(req, res, next) {
|
||||||
var user = res.locals.user,
|
var user = res.locals.user,
|
||||||
id = req.params.id,
|
id = req.params.id;
|
||||||
taskQuery = { userId: user._id };
|
|
||||||
|
|
||||||
if (validator.isUUID(id)) {
|
asyncM.waterfall([
|
||||||
taskQuery._id = id;
|
function (cb) {
|
||||||
} else {
|
Tasks.Task.findOne({
|
||||||
taskQuery._legacyId = id;
|
_id: id,
|
||||||
}
|
userId: user._id,
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
function (task, cb) {
|
||||||
|
if (task) return cb(null, task);
|
||||||
|
|
||||||
Tasks.Task.findOne(taskQuery, function (err, task) {
|
Tasks.Task.findOne({
|
||||||
|
_legacyId: id,
|
||||||
|
userId: user._id,
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
], function (err, task) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
if (!task) return res.status(404).json({err: shared.i18n.t('messageTaskNotFound')});
|
if (!task) return res.status(404).json({err: shared.i18n.t('messageTaskNotFound')});
|
||||||
res.status(200).json(task.toJSONV2());
|
res.status(200).json(task.toJSONV2());
|
||||||
@@ -853,13 +868,22 @@ api.updateTask = function(req, res, next) {
|
|||||||
|
|
||||||
req.body = Tasks.Task.fromJSONV2(req.body);
|
req.body = Tasks.Task.fromJSONV2(req.body);
|
||||||
|
|
||||||
if (validator.isUUID(id)) {
|
asyncM.waterfall([
|
||||||
taskQuery._id = id;
|
function (cb) {
|
||||||
} else {
|
Tasks.Task.findOne({
|
||||||
taskQuery._legacyId = id;
|
_id: id,
|
||||||
}
|
userId: user._id,
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
function (task, cb) {
|
||||||
|
if (task) return cb(null, task);
|
||||||
|
|
||||||
Tasks.Task.findOne(taskQuery, function(err, task) {
|
Tasks.Task.findOne({
|
||||||
|
_legacyId: id,
|
||||||
|
userId: user._id,
|
||||||
|
}, cb);
|
||||||
|
},
|
||||||
|
], function (err, task) {
|
||||||
if(err) return next(err);
|
if(err) return next(err);
|
||||||
if(!task) return res.status(404).json({err: 'Task not found.'})
|
if(!task) return res.status(404).json({err: 'Task not found.'})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user