Revert "API v3 [WIP] (#6144)"

This reverts commit 28f2e9c356.
This commit is contained in:
Blade Barringer
2016-05-23 07:53:14 -05:00
parent 28f2e9c356
commit 0a7b6b65e7
993 changed files with 12914 additions and 44919 deletions
+24 -34
View File
@@ -1,49 +1,39 @@
import i18n from '../i18n';
import preenTodos from '../libs/preenTodos';
import {
NotFound,
BadRequest,
} from '../libs/errors';
import _ from 'lodash';
// TODO used only in client, move there?
module.exports = function sortTask (user, req = {}) {
let id = _.get(req, 'params.id');
let to = _.get(req, 'query.to');
let fromParam = _.get(req, 'query.from');
let taskType = _.get(req, 'params.taskType');
let index = _.findIndex(user[`${taskType}s`], function findById (task) {
return task._id === id;
});
if (index === -1) {
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
module.exports = function(user, req, cb) {
var from, id, movedTask, preenedTasks, ref, task, tasks, to;
id = req.params.id;
ref = req.query, to = ref.to, from = ref.from;
task = user.tasks[id];
if (!task) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
}
if (!to && !fromParam) {
throw new BadRequest('?to=__&from=__ are required');
if (!((to != null) && (from != null))) {
return typeof cb === "function" ? cb('?to=__&from=__ are required') : void 0;
}
let tasks = user[`${taskType}s`];
if (taskType === 'todo') {
let preenedTasks = preenTodos(tasks);
tasks = user[task.type + "s"];
if (task.type === 'todo' && tasks[from] !== task) {
preenedTasks = preenTodos(tasks);
if (to !== -1) {
to = tasks.indexOf(preenedTasks[to]);
}
fromParam = tasks.indexOf(preenedTasks[fromParam]);
from = tasks.indexOf(preenedTasks[from]);
}
let movedTask = tasks.splice(fromParam, 1)[0];
if (tasks[from] !== task) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
}
movedTask = tasks.splice(from, 1)[0];
if (to === -1) {
tasks.push(movedTask);
} else {
tasks.splice(to, 0, movedTask);
}
return tasks;
return typeof cb === "function" ? cb(null, tasks) : void 0;
};