add tasks to user.tasksOrder or creation

This commit is contained in:
Matteo Pagliazzi
2015-11-28 18:18:28 +01:00
parent c2dac2c494
commit 454aa3731c

View File

@@ -1,6 +1,7 @@
import { authWithHeaders } from '../../middlewares/api-v3/auth';
import * as Tasks from '../../models/task';
import { NotFound } from '../../libs/api-v3/errors';
import Q from 'q';
let api = {};
@@ -25,8 +26,13 @@ api.createTask = {
let newTask = new Tasks[`${taskType.charAt(0).toUpperCase() + taskType.slice(1)}Model`](Tasks.Task.sanitize(req.body));
newTask.userId = user._id;
newTask.save()
.then((task) => res.respond(201, task))
user.tasksOrder[taskType].unshift(newTask._id);
Q.all([
newTask.save(),
user.save(),
])
.then(([task]) => res.respond(201, task))
.catch(next);
},
};