v3 adapt v2: lint client only shared ops and enable members integration tests

This commit is contained in:
Matteo Pagliazzi
2016-04-07 11:54:36 +02:00
parent d49847688e
commit 2d3fbe9f13
13 changed files with 121 additions and 108 deletions

View File

@@ -1,41 +1,50 @@
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(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];
module.exports = function sortTag (user, req = {}) {
let id = _.get(req, 'params.id');
let to = _.get(req, 'query.to');
let fromParam = _.get(req, 'query.from');
let task = user.tasks[id];
if (!task) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
}
if (!((to != null) && (from != null))) {
return typeof cb === "function" ? cb('?to=__&from=__ are required') : void 0;
if (!to && !fromParam) {
throw new BadRequest('?to=__&from=__ are required');
}
tasks = user[task.type + "s"];
if (task.type === 'todo' && tasks[from] !== task) {
preenedTasks = preenTodos(tasks);
let tasks = user[`${task.type}s`];
if (task.type === 'todo' && tasks[fromParam] !== task) {
let preenedTasks = preenTodos(tasks);
if (to !== -1) {
to = tasks.indexOf(preenedTasks[to]);
}
from = tasks.indexOf(preenedTasks[from]);
fromParam = tasks.indexOf(preenedTasks[fromParam]);
}
if (tasks[from] !== task) {
return typeof cb === "function" ? cb({
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
if (tasks[fromParam] !== task) {
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
}
movedTask = tasks.splice(from, 1)[0];
let movedTask = tasks.splice(fromParam, 1)[0];
if (to === -1) {
tasks.push(movedTask);
} else {
tasks.splice(to, 0, movedTask);
}
return typeof cb === "function" ? cb(null, tasks) : void 0;
return tasks;
};