mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
+25
-47
@@ -1,8 +1,6 @@
|
||||
const errors = require('../../errors');
|
||||
const {CREATE_ACTION, DELETE_ACTION} = require('../../perms/constants');
|
||||
const {
|
||||
IGNORE_FLAGS_AGAINST_STAFF,
|
||||
} = require('../../config');
|
||||
const { CREATE_ACTION, DELETE_ACTION } = require('../../perms/constants');
|
||||
const { IGNORE_FLAGS_AGAINST_STAFF } = require('../../config');
|
||||
|
||||
/**
|
||||
* getActionItem will return the item that is associated with the given action.
|
||||
@@ -12,21 +10,16 @@ const {
|
||||
* @param {Object} action the action being performed
|
||||
* @return {Promise} resolves to the referenced item
|
||||
*/
|
||||
const getActionItem = async (ctx, {item_id, item_type}) => {
|
||||
const {
|
||||
loaders: {
|
||||
Comments,
|
||||
Users,
|
||||
},
|
||||
} = ctx;
|
||||
const getActionItem = async (ctx, { item_id, item_type }) => {
|
||||
const { loaders: { Comments, Users } } = ctx;
|
||||
|
||||
switch (item_type) {
|
||||
case 'COMMENTS':
|
||||
return Comments.get.load(item_id);
|
||||
case 'USERS':
|
||||
return Users.getByID.load(item_id);
|
||||
default:
|
||||
return null;
|
||||
case 'COMMENTS':
|
||||
return Comments.get.load(item_id);
|
||||
case 'USERS':
|
||||
return Users.getByID.load(item_id);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -38,19 +31,14 @@ const getActionItem = async (ctx, {item_id, item_type}) => {
|
||||
* @param {Object} action the action being created
|
||||
* @return {Promise} resolves to the action created
|
||||
*/
|
||||
const createAction = async (ctx, {item_id, item_type, action_type, group_id, metadata = {}}) => {
|
||||
const {
|
||||
user = {},
|
||||
pubsub,
|
||||
connectors: {
|
||||
services: {
|
||||
Actions,
|
||||
},
|
||||
},
|
||||
} = ctx;
|
||||
const createAction = async (
|
||||
ctx,
|
||||
{ item_id, item_type, action_type, group_id, metadata = {} }
|
||||
) => {
|
||||
const { user = {}, pubsub, connectors: { services: { Actions } } } = ctx;
|
||||
|
||||
// Gets the item referenced by the action.
|
||||
const item = await getActionItem(ctx, {item_id, item_type});
|
||||
const item = await getActionItem(ctx, { item_id, item_type });
|
||||
if (!item || item === null) {
|
||||
throw errors.ErrNotFound;
|
||||
}
|
||||
@@ -59,7 +47,6 @@ const createAction = async (ctx, {item_id, item_type, action_type, group_id, met
|
||||
// staff member.
|
||||
if (IGNORE_FLAGS_AGAINST_STAFF) {
|
||||
if (action_type === 'FLAG') {
|
||||
|
||||
// If the item is a user, and this is a flag. Check to see if they are
|
||||
// staff, if they are, don't permit the flag.
|
||||
if (item_type === 'USERS' && item.isStaff()) {
|
||||
@@ -69,7 +56,6 @@ const createAction = async (ctx, {item_id, item_type, action_type, group_id, met
|
||||
}
|
||||
|
||||
if (action_type === 'FLAG' && item_type === 'USERS') {
|
||||
|
||||
// The item is a user, and this is a flag. Check to see if they are staff,
|
||||
// if they are, don't permit the flag.
|
||||
if (item.isStaff()) {
|
||||
@@ -84,11 +70,10 @@ const createAction = async (ctx, {item_id, item_type, action_type, group_id, met
|
||||
user_id: user.id,
|
||||
group_id,
|
||||
action_type,
|
||||
metadata
|
||||
metadata,
|
||||
});
|
||||
|
||||
if (action_type === 'FLAG' && item_type === 'COMMENTS') {
|
||||
|
||||
// The item is a comment, and this is a flag. Push that the comment was
|
||||
// flagged, don't wait for it to finish.
|
||||
pubsub.publish('commentFlagged', item);
|
||||
@@ -104,33 +89,26 @@ const createAction = async (ctx, {item_id, item_type, action_type, group_id, met
|
||||
* @param {String} id the id of the action to delete
|
||||
* @return {Promise} resolves to the deleted action, or null if not found.
|
||||
*/
|
||||
const deleteAction = (ctx, {id}) => {
|
||||
const {
|
||||
user,
|
||||
connectors: {
|
||||
services: {
|
||||
Actions,
|
||||
},
|
||||
},
|
||||
} = ctx;
|
||||
const deleteAction = (ctx, { id }) => {
|
||||
const { user, connectors: { services: { Actions } } } = ctx;
|
||||
|
||||
return Actions.delete({id, user_id: user.id});
|
||||
return Actions.delete({ id, user_id: user.id });
|
||||
};
|
||||
|
||||
module.exports = (ctx) => {
|
||||
module.exports = ctx => {
|
||||
let mutators = {
|
||||
Action: {
|
||||
create: () => Promise.reject(errors.ErrNotAuthorized),
|
||||
delete: () => Promise.reject(errors.ErrNotAuthorized)
|
||||
}
|
||||
delete: () => Promise.reject(errors.ErrNotAuthorized),
|
||||
},
|
||||
};
|
||||
|
||||
if (ctx.user && ctx.user.can(CREATE_ACTION)) {
|
||||
mutators.Action.create = (action) => createAction(ctx, action);
|
||||
mutators.Action.create = action => createAction(ctx, action);
|
||||
}
|
||||
|
||||
if (ctx.user && ctx.user.can(DELETE_ACTION)) {
|
||||
mutators.Action.delete = (action) => deleteAction(ctx, action);
|
||||
mutators.Action.delete = action => deleteAction(ctx, action);
|
||||
}
|
||||
|
||||
return mutators;
|
||||
|
||||
Reference in New Issue
Block a user