Merge branch 'master' into dont-agree

This commit is contained in:
David Jay
2017-02-21 15:02:33 -05:00
committed by GitHub
52 changed files with 726 additions and 859 deletions
+17 -3
View File
@@ -1,3 +1,6 @@
const {Error: {ValidationError}} = require('mongoose');
const errors = require('../../errors');
/**
* Wraps up a promise to return an object with the resolution of the promise
* keyed at `key` or an error caught at `errors`.
@@ -9,9 +12,20 @@ const wrapResponse = (key) => (promise) => {
res[key] = value;
}
return res;
}).catch((err) => ({
errors: [err]
}));
}).catch((err) => {
if (err instanceof errors.APIError) {
return {
errors: [err]
};
} else if (err instanceof ValidationError) {
// TODO: wrap this with one of our internal errors.
throw err;
}
throw err;
});
};
const RootMutation = {
+17
View File
@@ -39,6 +39,23 @@ const RootQuery = {
return Comments.getByQuery(query);
},
commentCount(_, {query: {action_type, statuses, asset_id, parent_id}}, {user, loaders: {Actions, Comments}}) {
if (user == null || !user.hasRoles('ADMIN')) {
return null;
}
if (action_type) {
return Actions.getByTypes({action_type, item_type: 'COMMENTS'})
.then((ids) => {
// Perform the query using the available resolver.
return Comments.getCountByQuery({ids, statuses, asset_id, parent_id});
});
}
return Comments.getCountByQuery({statuses, asset_id, parent_id});
},
metrics(_, {from, to, sort, limit = 10}, {user, loaders: {Metrics}}) {
if (user == null || !user.hasRoles('ADMIN')) {
return null;