habitica-self-host/common/script/ops/deleteTask.js

18 lines
475 B
JavaScript
Raw Normal View History

2016-03-07 22:02:42 +00:00
import i18n from '../i18n';
2016-03-08 16:45:14 +00:00
module.exports = function(user, req, cb) {
2016-03-07 22:02:42 +00:00
var i, ref, task;
2016-03-08 16:45:14 +00:00
task = user.tasks[(ref = req.params) != null ? ref.id : void 0];
2016-03-07 22:02:42 +00:00
if (!task) {
2016-03-08 16:45:14 +00:00
return typeof cb === "function" ? cb({
2016-03-07 22:02:42 +00:00
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
}
2016-03-08 16:45:14 +00:00
i = user[task.type + "s"].indexOf(task);
2016-03-07 22:02:42 +00:00
if (~i) {
2016-03-08 16:45:14 +00:00
user[task.type + "s"].splice(i, 1);
2016-03-07 22:02:42 +00:00
}
2016-03-08 16:45:14 +00:00
return typeof cb === "function" ? cb(null, {}) : void 0;
2016-03-07 22:02:42 +00:00
};