From 2956ae04624eb4b33265f425ed5d26865b1b63f5 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Thu, 12 Dec 2013 17:32:02 -0700 Subject: [PATCH] move sortTask to user.ops [https://github.com/HabitRPG/habitrpg/issues/1977] [https://github.com/HabitRPG/habitrpg/issues/1616] --- dist/habitrpg-shared.js | 17 +++++++++++++++++ script/index.coffee | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index f41c126eab..5c24dca32d 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -10927,6 +10927,23 @@ var process=require("__browserify_process");(function() { }); return typeof cb === "function" ? cb(null, req) : void 0; }, + sortTask: function(req, cb) { + var from, id, task, to, _ref; + id = req.params.id; + _ref = req.query, to = _ref.to, from = _ref.from; + task = user.tasks[id]; + if (!task) { + return cb({ + code: 404, + message: "No task found." + }); + } + if (!((to != null) && (from != null))) { + return cb('?to=__&from=__ are required'); + } + user["" + task.type + "s"].splice(to, 0, user["" + task.type + "s"].splice(from, 1)[0]); + return cb(null, req); + }, updateTask: function(req, cb) { if (!(req.params.id && user.tasks[req.params.id])) { return typeof cb === "function" ? cb("Task not found") : void 0; diff --git a/script/index.coffee b/script/index.coffee index 7f59baf801..38894d7749 100644 --- a/script/index.coffee +++ b/script/index.coffee @@ -642,6 +642,15 @@ api.wrap = (user) -> user.fns.dotSet(k,v) cb? null, req + sortTask: (req, cb) -> + {id} = req.params + {to, from} = req.query + task = user.tasks[id] + return cb({code:404, message: "No task found."}) unless task + return cb('?to=__&from=__ are required') unless to? and from? + user["#{task.type}s"].splice to, 0, user["#{task.type}s"].splice(from, 1)[0] + cb null, req + updateTask: (req, cb) -> return cb?("Task not found") unless req.params.id and user.tasks[req.params.id] _.merge user.tasks[req.params.id], req.body