v3 adapt v2: lint client only shared ops and enable members integration tests
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import uuid from '../libs/uuid';
|
||||
import _ from 'lodash';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
if (user.tags == null) {
|
||||
module.exports = function addTag (user, req = {}) {
|
||||
if (!user.tags) {
|
||||
user.tags = [];
|
||||
}
|
||||
|
||||
user.tags.push({
|
||||
name: req.body.name,
|
||||
id: req.body.id || uuid()
|
||||
id: _.get(req, 'body.id') || uuid(),
|
||||
});
|
||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
||||
|
||||
return user.tags;
|
||||
};
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import { NotFound } from '../libs/errors';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
var i, tag, tid;
|
||||
tid = req.params.id;
|
||||
i = _.findIndex(user.tags, {
|
||||
id: tid
|
||||
module.exports = function deleteTag (user, req = {}) {
|
||||
let tid = _.get(req, 'params.id');
|
||||
|
||||
let index = _.findIndex(user.tags, {
|
||||
id: tid,
|
||||
});
|
||||
if (!~i) {
|
||||
return typeof cb === "function" ? cb({
|
||||
code: 404,
|
||||
message: i18n.t('messageTagNotFound', req.language)
|
||||
}) : void 0;
|
||||
|
||||
if (index === -1) {
|
||||
throw new NotFound(i18n.t('messageTagNotFound', req.language));
|
||||
}
|
||||
tag = user.tags[i];
|
||||
|
||||
let tag = user.tags[index];
|
||||
delete user.filters[tag.id];
|
||||
user.tags.splice(i, 1);
|
||||
_.each(user.tasks, function(task) {
|
||||
|
||||
user.tags.splice(index, 1);
|
||||
|
||||
_.each(user.tasks, (task) => {
|
||||
return delete task.tags[tag.id];
|
||||
});
|
||||
_.each(['habits', 'dailys', 'todos', 'rewards'], function(type) {
|
||||
return typeof user.markModified === "function" ? user.markModified(type) : void 0;
|
||||
|
||||
_.each(['habits', 'dailys', 'todos', 'rewards'], (type) => {
|
||||
user.markModified(type);
|
||||
});
|
||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
||||
|
||||
return user.tags;
|
||||
};
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import i18n from '../i18n';
|
||||
import { NotFound } from '../libs/errors';
|
||||
import _ from 'lodash';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
var i, ref, task;
|
||||
task = user.tasks[(ref = req.params) != null ? ref.id : void 0];
|
||||
module.exports = function deleteTask (user, req = {}) {
|
||||
let tid = _.get(req, 'params.id');
|
||||
let task = user.tasks[tid];
|
||||
|
||||
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));
|
||||
}
|
||||
i = user[task.type + "s"].indexOf(task);
|
||||
if (~i) {
|
||||
user[task.type + "s"].splice(i, 1);
|
||||
|
||||
let index = user[`${task.type}s`].indexOf(task);
|
||||
if (index !== -1) {
|
||||
user[`${task.type}s`].splice(index, 1);
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, {}) : void 0;
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
+10
-11
@@ -1,19 +1,18 @@
|
||||
import _ from 'lodash';
|
||||
import i18n from '../i18n';
|
||||
import { NotFound } from '../libs/errors';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
var i, tid;
|
||||
tid = req.params.id;
|
||||
i = _.findIndex(user.tags, {
|
||||
id: tid
|
||||
module.exports = function getTag (user, req = {}) {
|
||||
let tid = _.get(req, 'params.id');
|
||||
|
||||
let index = _.findIndex(user.tags, {
|
||||
id: tid,
|
||||
});
|
||||
if (!~i) {
|
||||
return typeof cb === "function" ? cb({
|
||||
code: 404,
|
||||
message: i18n.t('messageTagNotFound', req.language)
|
||||
}) : void 0;
|
||||
if (index === -1) {
|
||||
throw new NotFound(i18n.t('messageTagNotFound', req.language));
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, user.tags[i]) : void 0;
|
||||
|
||||
return user.tags[index];
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
||||
module.exports = function getTags (user) {
|
||||
return user.tags;
|
||||
};
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { BadRequest } from '../libs/errors';
|
||||
import _ from 'lodash';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
var from, ref, to;
|
||||
ref = req.query, to = ref.to, from = ref.from;
|
||||
if (!((to != null) && (from != null))) {
|
||||
return typeof cb === "function" ? cb('?to=__&from=__ are required') : void 0;
|
||||
module.exports = function sortTag (user, req = {}) {
|
||||
let to = _.get(req, 'query.to');
|
||||
let fromParam = _.get(req, 'query.from');
|
||||
|
||||
if (!to || !fromParam) {
|
||||
throw new BadRequest('?to=__&from=__ are required');
|
||||
}
|
||||
user.tags.splice(to, 0, user.tags.splice(from, 1)[0]);
|
||||
return typeof cb === "function" ? cb(null, user.tags) : void 0;
|
||||
|
||||
user.tags.splice(to, 0, user.tags.splice(fromParam, 1)[0]);
|
||||
return user.tags;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
_.each(req.body, function(v, k) {
|
||||
user.fns.dotSet(k, v);
|
||||
return true;
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function updateUser (user, req = {}) {
|
||||
_.each(req.body, (val, key) => {
|
||||
_.set(user, key, val);
|
||||
});
|
||||
return typeof cb === "function" ? cb(null, user) : void 0;
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import { NotFound } from '../libs/errors';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
var i, tid;
|
||||
tid = req.params.id;
|
||||
i = _.findIndex(user.tags, {
|
||||
id: tid
|
||||
module.exports = function updateTag (user, req = {}) {
|
||||
let tid = _.get(req, 'params.id');
|
||||
|
||||
let index = _.findIndex(user.tags, {
|
||||
id: tid,
|
||||
});
|
||||
if (!~i) {
|
||||
return typeof cb === "function" ? cb({
|
||||
code: 404,
|
||||
message: i18n.t('messageTagNotFound', req.language)
|
||||
}) : void 0;
|
||||
|
||||
if (index === -1) {
|
||||
throw new NotFound(i18n.t('messageTagNotFound', req.language));
|
||||
}
|
||||
user.tags[i].name = req.body.name;
|
||||
return typeof cb === "function" ? cb(null, user.tags[i]) : void 0;
|
||||
|
||||
user.tags[index].name = _.get(req, 'body.name');
|
||||
return user.tags[index];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user