cleanup to mutators

This commit is contained in:
Wyatt Johnson
2017-05-11 17:31:22 -06:00
parent d497ad3369
commit 547ba126be
3 changed files with 11 additions and 10 deletions
+7 -7
View File
@@ -172,7 +172,7 @@ const createPublicComment = async (context, commentInput) => {
* @param {String} status the new status of the comment
*/
const setCommentStatus = async ({user, loaders: {Comments}}, {id, status}) => {
const setStatus = async ({user, loaders: {Comments}}, {id, status}) => {
let comment = await CommentsService.pushStatus(id, status, user ? user.id : null);
// If the loaders are present, clear the caches for these values because we
@@ -215,7 +215,7 @@ const removeCommentTag = ({user, loaders: {Comments}}, {id, tag}) => {
* @param {Object} edit describes how to edit the comment
* @param {String} edit.body the new Comment body
*/
const editComment = async (context, {id, asset_id, edit: {body}}) => {
const edit = async (context, {id, asset_id, edit: {body}}) => {
// Get the wordlist and the settings object.
const [wordlist, settings] = await filterNewComment(context, {asset_id, body});
@@ -232,10 +232,10 @@ module.exports = (context) => {
let mutators = {
Comment: {
create: () => Promise.reject(errors.ErrNotAuthorized),
setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized),
setStatus: () => Promise.reject(errors.ErrNotAuthorized),
addCommentTag: () => Promise.reject(errors.ErrNotAuthorized),
removeCommentTag: () => Promise.reject(errors.ErrNotAuthorized),
editComment: () => Promise.reject(errors.ErrNotAuthorized),
edit: () => Promise.reject(errors.ErrNotAuthorized),
}
};
@@ -244,7 +244,7 @@ module.exports = (context) => {
}
if (context.user && context.user.can('mutation:setCommentStatus')) {
mutators.Comment.setCommentStatus = (action) => setCommentStatus(context, action);
mutators.Comment.setStatus = (action) => setStatus(context, action);
}
if (context.user && context.user.can('mutation:addCommentTag')) {
@@ -255,8 +255,8 @@ module.exports = (context) => {
mutators.Comment.removeCommentTag = (action) => removeCommentTag(context, action);
}
if (context.user) {
mutators.Comment.editComment = (action) => editComment(context, action);
if (context.user && context.user.can('mutation:editComment')) {
mutators.Comment.edit = (action) => edit(context, action);
}
return mutators;
+2 -2
View File
@@ -6,7 +6,7 @@ const RootMutation = {
return wrapResponse('comment')(Comment.create(comment));
},
editComment(_, args, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.editComment(args));
return wrapResponse('comment')(Comment.edit(args));
},
createFlag(_, {flag: {item_id, item_type, reason, message}}, {mutators: {Action}}) {
return wrapResponse('flag')(Action.create({item_id, item_type, action_type: 'FLAG', group_id: reason, metadata: {message}}));
@@ -30,7 +30,7 @@ const RootMutation = {
return wrapResponse(null)(User.stopIgnoringUser({id}));
},
setCommentStatus(_, {id, status}, {mutators: {Comment}}) {
return wrapResponse(null)(Comment.setCommentStatus({id, status}));
return wrapResponse(null)(Comment.setStatus({id, status}));
},
addCommentTag(_, {id, tag}, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.addCommentTag({id, tag}).then(() => CommentsService.findById(id)));
+2 -1
View File
@@ -199,7 +199,8 @@ const USER_GRAPH_OPERATIONS = [
'mutation:suspendUser',
'mutation:setCommentStatus',
'mutation:addCommentTag',
'mutation:removeCommentTag'
'mutation:removeCommentTag',
'mutation:editComment'
];
/**