Updated login headers save. Added task service to user service. Sync user tasks

This commit is contained in:
Keith Holliday
2016-05-09 23:31:34 -05:00
parent a92359e119
commit a0939155c9
13 changed files with 107 additions and 86 deletions

View File

@@ -8,23 +8,24 @@ import _ from 'lodash';
// TODO used only in client, move there?
module.exports = function sortTag (user, req = {}) {
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 task = user.tasks[id];
let index = _.findIndex(user[`${taskType}s`], function(task) {return task._id === id;});
if (!task) {
if (index === -1) {
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
}
if (!to && !fromParam) {
throw new BadRequest('?to=__&from=__ are required');
}
let tasks = user[`${task.type}s`];
let tasks = user[`${taskType}s`];
if (task.type === 'todo' && tasks[fromParam] !== task) {
if (taskType === 'todo') {
let preenedTasks = preenTodos(tasks);
if (to !== -1) {
@@ -34,10 +35,6 @@ module.exports = function sortTag (user, req = {}) {
fromParam = tasks.indexOf(preenedTasks[fromParam]);
}
if (tasks[fromParam] !== task) {
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
}
let movedTask = tasks.splice(fromParam, 1)[0];
if (to === -1) {