finish implementing tasks syncing for challenges

This commit is contained in:
Matteo Pagliazzi
2016-01-05 20:19:55 +01:00
parent 3bc8945bcc
commit a5b1dfd32d
4 changed files with 123 additions and 88 deletions
+6 -5
View File
@@ -112,12 +112,13 @@ api.getGroups = {
// If no valid value for type was supplied, return an error
if (queries.length === 0) throw new BadRequest(res.t('groupTypesRequired'));
let results = await Q.all(queries); // TODO we would like not to return a single big array but Q doesn't support the funtionality https://github.com/kriskowal/q/issues/328
// TODO we would like not to return a single big array but Q doesn't support the funtionality https://github.com/kriskowal/q/issues/328
let results = _.reduce(await Q.all(queries), (previousValue, currentValue) => {
if (_.isEmpty(currentValue)) return previousValue; // don't add anything to the results if the query returned null or an empty array
return previousValue.concat(Array.isArray(currentValue) ? currentValue : [currentValue]); // otherwise concat the new results to the previousValue
}, []);
res.respond(200, _.reduce(results, (m, v) => {
if (_.isEmpty(v)) return m;
return m.concat(Array.isArray(v) ? v : [v]);
}, []));
res.respond(200, results);
},
};
+2 -2
View File
@@ -35,8 +35,8 @@ api.createTask = {
req.checkQuery('tasksOwner', res.t('invalidTasksOwner')).isIn(['user', 'challenge']);
req.checkQuery('challengeId', res.t('challengeIdRequired')).optional().isUUID();
let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
let reqValidationErrors = req.validationErrors();
if (reqValidationErrors) throw reqValidationErrors;
let tasksData = Array.isArray(req.body) ? req.body : [req.body];
let user = res.locals.user;