mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-03 04:29:40 +00:00
apiv2: move tags (update, delete, create) to Shared.ops
This commit is contained in:
parent
ab27840a61
commit
7e8ae43958
2 changed files with 72 additions and 0 deletions
43
dist/habitrpg-shared.js
vendored
43
dist/habitrpg-shared.js
vendored
|
|
@ -11005,6 +11005,49 @@ var process=require("__browserify_process");(function() {
|
||||||
}
|
}
|
||||||
return task;
|
return task;
|
||||||
},
|
},
|
||||||
|
addTag: function(req, cb) {
|
||||||
|
var name;
|
||||||
|
name = req.body.name;
|
||||||
|
if (user.tags == null) {
|
||||||
|
user.tags = [];
|
||||||
|
}
|
||||||
|
user.tags.push({
|
||||||
|
name: name
|
||||||
|
});
|
||||||
|
return typeof cb === "function" ? cb(null, req) : void 0;
|
||||||
|
},
|
||||||
|
updateTag: function(req, cb) {
|
||||||
|
var i, tid;
|
||||||
|
tid = req.params.id;
|
||||||
|
i = _.findIndex(user.tags, {
|
||||||
|
id: tid
|
||||||
|
});
|
||||||
|
if (!~i) {
|
||||||
|
return cb('Tag not found', req);
|
||||||
|
}
|
||||||
|
user.tags[i].name = req.body.name;
|
||||||
|
return typeof cb === "function" ? cb(null, req) : void 0;
|
||||||
|
},
|
||||||
|
deleteTag: function(req, cb) {
|
||||||
|
var i, tag, tid;
|
||||||
|
tid = req.params.id;
|
||||||
|
i = _.findIndex(user.tags, {
|
||||||
|
id: tid
|
||||||
|
});
|
||||||
|
if (!~i) {
|
||||||
|
return cb('Tag not found', req);
|
||||||
|
}
|
||||||
|
tag = user.tags[i];
|
||||||
|
delete user.filters[tag.id];
|
||||||
|
user.tags.splice(i, 1);
|
||||||
|
_.each(user.tasks, function(task) {
|
||||||
|
return delete task.tags[tag.id];
|
||||||
|
});
|
||||||
|
_.each(['habits', 'dailys', 'todos', 'rewards'], function(type) {
|
||||||
|
return typeof user.markModified === "function" ? user.markModified(type) : void 0;
|
||||||
|
});
|
||||||
|
return cb(null, req);
|
||||||
|
},
|
||||||
feed: function(req, cb) {
|
feed: function(req, cb) {
|
||||||
var egg, evolve, food, message, pet, potion, userPets, _ref, _ref1, _ref2, _ref3;
|
var egg, evolve, food, message, pet, potion, userPets, _ref, _ref1, _ref2, _ref3;
|
||||||
_ref2 = [(_ref = req.query) != null ? _ref.pet : void 0, content.food[(_ref1 = req.query) != null ? _ref1.food : void 0]], pet = _ref2[0], food = _ref2[1];
|
_ref2 = [(_ref = req.query) != null ? _ref.pet : void 0, content.food[(_ref1 = req.query) != null ? _ref1.food : void 0]], pet = _ref2[0], food = _ref2[1];
|
||||||
|
|
|
||||||
|
|
@ -348,6 +348,35 @@ api.wrap = (user) ->
|
||||||
cb? null, req
|
cb? null, req
|
||||||
task
|
task
|
||||||
|
|
||||||
|
addTag: (req, cb) ->
|
||||||
|
{name} = req.body
|
||||||
|
user.tags ?= []
|
||||||
|
user.tags.push({name})
|
||||||
|
cb? null, req
|
||||||
|
|
||||||
|
updateTag: (req, cb) ->
|
||||||
|
tid = req.params.id
|
||||||
|
i = _.findIndex user.tags, {id: tid}
|
||||||
|
return cb('Tag not found', req) if !~i
|
||||||
|
user.tags[i].name = req.body.name
|
||||||
|
cb? null, req
|
||||||
|
|
||||||
|
deleteTag: (req, cb) ->
|
||||||
|
tid = req.params.id
|
||||||
|
i = _.findIndex user.tags, {id: tid}
|
||||||
|
return cb('Tag not found', req) if !~i
|
||||||
|
tag = user.tags[i]
|
||||||
|
delete user.filters[tag.id]
|
||||||
|
user.tags.splice i, 1
|
||||||
|
|
||||||
|
# remove tag from all tasks
|
||||||
|
_.each user.tasks, (task) ->
|
||||||
|
delete task.tags[tag.id]
|
||||||
|
|
||||||
|
_.each ['habits','dailys','todos','rewards'], (type) ->
|
||||||
|
user.markModified? type
|
||||||
|
cb null, req
|
||||||
|
|
||||||
feed: (req, cb) ->
|
feed: (req, cb) ->
|
||||||
[pet, food] = [req.query?.pet, content.food[req.query?.food]]
|
[pet, food] = [req.query?.pet, content.food[req.query?.food]]
|
||||||
[egg, potion] = pet.split('-')
|
[egg, potion] = pet.split('-')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue