mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
Resolve linter issues
This commit is contained in:
+3
-1
@@ -149,7 +149,9 @@ class Context {
|
||||
* operations.
|
||||
*/
|
||||
static forSystem() {
|
||||
const { models: { User } } = connectors;
|
||||
const {
|
||||
models: { User },
|
||||
} = connectors;
|
||||
|
||||
// Create the system user.
|
||||
const user = new User({ system: true });
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
const { forEachField } = require('./utils');
|
||||
const { maskErrors } = require('graphql-errors');
|
||||
const { TalkError } = require('../errors');
|
||||
const { Error: { ValidationError } } = require('mongoose');
|
||||
const {
|
||||
Error: { ValidationError },
|
||||
} = require('mongoose');
|
||||
|
||||
// If an APIError happens in a mutation, then respond with `{errors: Array}`
|
||||
// according to the schema.
|
||||
|
||||
@@ -6,7 +6,11 @@ const { first, get, merge, remove, groupBy, reduce, isNil } = require('lodash');
|
||||
* Gets actions based on their item id's.
|
||||
*/
|
||||
const genActionsByItemID = (
|
||||
{ connectors: { services: { Actions } } },
|
||||
{
|
||||
connectors: {
|
||||
services: { Actions },
|
||||
},
|
||||
},
|
||||
item_ids
|
||||
) => {
|
||||
return Actions.findByItemIdArray(item_ids).then(
|
||||
@@ -21,7 +25,12 @@ const genActionsByItemID = (
|
||||
* @param {Array<String>} itemIDs the items that we need to get the actions for
|
||||
*/
|
||||
const genActionsAuthoredWithID = (
|
||||
{ user = {}, connectors: { services: { Actions } } },
|
||||
{
|
||||
user = {},
|
||||
connectors: {
|
||||
services: { Actions },
|
||||
},
|
||||
},
|
||||
itemIDs
|
||||
) =>
|
||||
Actions.getUserActions(user.id, itemIDs).then(
|
||||
@@ -50,7 +59,9 @@ const iterateActionCounts = action_counts =>
|
||||
* @param {Object} item the item that we're getting the actions for
|
||||
*/
|
||||
async function getUserActions(ctx, { action_counts, id }) {
|
||||
const { loaders: { Actions } } = ctx;
|
||||
const {
|
||||
loaders: { Actions },
|
||||
} = ctx;
|
||||
|
||||
// Get the total count for all action types.
|
||||
const totalActionCount = reduce(
|
||||
|
||||
+19
-3
@@ -2,7 +2,14 @@ const DataLoader = require('dataloader');
|
||||
const { URL } = require('url');
|
||||
const { singleJoinBy, SingletonResolver } = require('./util');
|
||||
|
||||
const genAssetsByID = ({ connectors: { models: { Asset } } }, ids) =>
|
||||
const genAssetsByID = (
|
||||
{
|
||||
connectors: {
|
||||
models: { Asset },
|
||||
},
|
||||
},
|
||||
ids
|
||||
) =>
|
||||
Asset.find({
|
||||
id: {
|
||||
$in: ids,
|
||||
@@ -10,7 +17,11 @@ const genAssetsByID = ({ connectors: { models: { Asset } } }, ids) =>
|
||||
}).then(singleJoinBy(ids, 'id'));
|
||||
|
||||
const getAssetsByQuery = async (
|
||||
{ connectors: { services: { Assets } } },
|
||||
{
|
||||
connectors: {
|
||||
services: { Assets },
|
||||
},
|
||||
},
|
||||
query
|
||||
) => {
|
||||
// If we are requesting based on a limit, ask for one more than we want.
|
||||
@@ -126,7 +137,12 @@ const findOrCreateAssetByURL = async (ctx, url) => {
|
||||
};
|
||||
|
||||
const findByUrl = async (
|
||||
{ connectors: { errors, services: { Assets } } },
|
||||
{
|
||||
connectors: {
|
||||
errors,
|
||||
services: { Assets },
|
||||
},
|
||||
},
|
||||
asset_url
|
||||
) => {
|
||||
// Try to validate that the url is valid. If the URL constructor throws an
|
||||
|
||||
+17
-3
@@ -51,7 +51,11 @@ const genUserByIDs = async (ctx, ids) => {
|
||||
return [];
|
||||
}
|
||||
|
||||
const { connectors: { models: { User } } } = ctx;
|
||||
const {
|
||||
connectors: {
|
||||
models: { User },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
return User.find({ id: { $in: ids } }).then(util.singleJoinBy(ids, 'id'));
|
||||
};
|
||||
@@ -63,7 +67,12 @@ const genUserByIDs = async (ctx, ids) => {
|
||||
* @param {Object} query query terms to apply to the users query
|
||||
*/
|
||||
const getUsersByQuery = async (
|
||||
{ user, connectors: { models: { User } } },
|
||||
{
|
||||
user,
|
||||
connectors: {
|
||||
models: { User },
|
||||
},
|
||||
},
|
||||
{ limit, cursor, value = '', state, action_type, sortOrder }
|
||||
) => {
|
||||
let query = User.find();
|
||||
@@ -175,7 +184,12 @@ const getUsersByQuery = async (
|
||||
* query
|
||||
*/
|
||||
const getCountByQuery = async (
|
||||
{ user, connectors: { models: { User } } },
|
||||
{
|
||||
user,
|
||||
connectors: {
|
||||
models: { User },
|
||||
},
|
||||
},
|
||||
{ action_type, state }
|
||||
) => {
|
||||
const query = User.find();
|
||||
|
||||
@@ -11,7 +11,9 @@ const { IGNORE_FLAGS_AGAINST_STAFF } = require('../../config');
|
||||
* @return {Promise} resolves to the referenced item
|
||||
*/
|
||||
const getActionItem = async (ctx, { item_id, item_type }) => {
|
||||
const { loaders: { Comments, Users } } = ctx;
|
||||
const {
|
||||
loaders: { Comments, Users },
|
||||
} = ctx;
|
||||
|
||||
switch (item_type) {
|
||||
case 'COMMENTS': {
|
||||
@@ -42,7 +44,13 @@ const createAction = async (
|
||||
ctx,
|
||||
{ item_id, item_type, action_type, group_id, metadata = {} }
|
||||
) => {
|
||||
const { user = {}, pubsub, connectors: { services: { Actions } } } = ctx;
|
||||
const {
|
||||
user = {},
|
||||
pubsub,
|
||||
connectors: {
|
||||
services: { Actions },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
// Gets the item referenced by the action.
|
||||
const item = await getActionItem(ctx, { item_id, item_type });
|
||||
@@ -107,7 +115,12 @@ const createAction = async (
|
||||
* @return {Promise} resolves to the deleted action, or null if not found.
|
||||
*/
|
||||
const deleteAction = (ctx, { id }) => {
|
||||
const { user, connectors: { services: { Actions } } } = ctx;
|
||||
const {
|
||||
user,
|
||||
connectors: {
|
||||
services: { Actions },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
return Actions.delete({ id, user_id: user.id });
|
||||
};
|
||||
|
||||
@@ -63,7 +63,11 @@ const closeNow = async (ctx, id) =>
|
||||
* @param {String} id the asset's id to scrape
|
||||
*/
|
||||
const scrapeAsset = async (ctx, id) => {
|
||||
const { connectors: { services: { Scraper } } } = ctx;
|
||||
const {
|
||||
connectors: {
|
||||
services: { Scraper },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
return Scraper.create(ctx, id);
|
||||
};
|
||||
|
||||
@@ -14,7 +14,10 @@ const {
|
||||
} = require('../../perms/constants');
|
||||
|
||||
const resolveTagsForComment = async (ctx, { asset_id, tags = [] }) => {
|
||||
const { user, loaders: { Tags } } = ctx;
|
||||
const {
|
||||
user,
|
||||
loaders: { Tags },
|
||||
} = ctx;
|
||||
const item_type = 'COMMENTS';
|
||||
|
||||
// Handle Tags
|
||||
@@ -156,7 +159,11 @@ const createComment = async (
|
||||
metadata = {},
|
||||
}
|
||||
) => {
|
||||
const { user, loaders: { Comments }, pubsub } = ctx;
|
||||
const {
|
||||
user,
|
||||
loaders: { Comments },
|
||||
pubsub,
|
||||
} = ctx;
|
||||
|
||||
// Resolve the tags for the comment.
|
||||
tags = await resolveTagsForComment(ctx, { asset_id, tags });
|
||||
@@ -202,7 +209,11 @@ const createComment = async (
|
||||
* @return {Promise} resolves to a new comment
|
||||
*/
|
||||
const createPublicComment = async (ctx, comment) => {
|
||||
const { connectors: { services: { Moderation } } } = ctx;
|
||||
const {
|
||||
connectors: {
|
||||
services: { Moderation },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
// We then take the wordlist and the comment into consideration when
|
||||
// considering what status to assign the new comment, and resolve the new
|
||||
@@ -245,7 +256,10 @@ const createActions = async (item_id, actions = []) =>
|
||||
* @param {String} status the new status of the comment
|
||||
*/
|
||||
const setStatus = async (ctx, { id, status }) => {
|
||||
const { user, loaders: { Comments } } = ctx;
|
||||
const {
|
||||
user,
|
||||
loaders: { Comments },
|
||||
} = ctx;
|
||||
|
||||
let comment = await CommentsService.pushStatus(
|
||||
id,
|
||||
@@ -281,7 +295,11 @@ const editComment = async (
|
||||
ctx,
|
||||
{ id, asset_id, edit: { body, metadata = {} } }
|
||||
) => {
|
||||
const { connectors: { services: { Moderation } } } = ctx;
|
||||
const {
|
||||
connectors: {
|
||||
services: { Moderation },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
// Build up the new comment we're setting. We need to check this with
|
||||
// moderation now.
|
||||
|
||||
@@ -92,7 +92,11 @@ const actionDecrTransformer = ({ item_id, action_type, group_id }) => {
|
||||
|
||||
// delUser will delete a given user with the specified id.
|
||||
const delUser = async (ctx, id) => {
|
||||
const { connectors: { models: { User, Action, Comment } } } = ctx;
|
||||
const {
|
||||
connectors: {
|
||||
models: { User, Action, Comment },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
// Find the user we're removing.
|
||||
const user = await User.findOne({ id });
|
||||
@@ -178,7 +182,9 @@ const changeUserPassword = async (ctx, oldPassword, newPassword) => {
|
||||
const {
|
||||
user,
|
||||
loaders: { Settings },
|
||||
connectors: { services: { I18n } },
|
||||
connectors: {
|
||||
services: { I18n },
|
||||
},
|
||||
} = ctx;
|
||||
|
||||
// Verify the old password.
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
const { decorateWithTags, getRequestedFields } = require('./util');
|
||||
|
||||
const Asset = {
|
||||
async comment({ id }, { id: commentId }, { loaders: { Comments } }) {
|
||||
async comment(
|
||||
{ id },
|
||||
{ id: commentId },
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
// Load the comment from the database.
|
||||
const comment = await Comments.get.load(commentId);
|
||||
if (!comment) {
|
||||
@@ -15,7 +21,13 @@ const Asset = {
|
||||
|
||||
return comment;
|
||||
},
|
||||
comments({ id }, { query, deep }, { loaders: { Comments } }) {
|
||||
comments(
|
||||
{ id },
|
||||
{ query, deep },
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
if (!deep) {
|
||||
query.parent_id = null;
|
||||
}
|
||||
@@ -25,7 +37,13 @@ const Asset = {
|
||||
|
||||
return Comments.getByQuery(query);
|
||||
},
|
||||
commentCount({ id, commentCount }, { tags }, { loaders: { Comments } }) {
|
||||
commentCount(
|
||||
{ id, commentCount },
|
||||
{ tags },
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
if (commentCount != null) {
|
||||
return commentCount;
|
||||
}
|
||||
@@ -46,7 +64,9 @@ const Asset = {
|
||||
totalCommentCount(
|
||||
{ id, totalCommentCount },
|
||||
{ tags },
|
||||
{ loaders: { Comments } }
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
if (totalCommentCount != null) {
|
||||
return totalCommentCount;
|
||||
@@ -64,7 +84,14 @@ const Asset = {
|
||||
|
||||
return Comments.countByAssetID.load(id);
|
||||
},
|
||||
async settings({ settings = null }, _, { loaders: { Settings } }, info) {
|
||||
async settings(
|
||||
{ settings = null },
|
||||
_,
|
||||
{
|
||||
loaders: { Settings },
|
||||
},
|
||||
info
|
||||
) {
|
||||
// Get the fields we want from the settings.
|
||||
const fields = getRequestedFields(info);
|
||||
|
||||
|
||||
@@ -16,19 +16,37 @@ const Comment = {
|
||||
hasParent({ parent_id }) {
|
||||
return !!parent_id;
|
||||
},
|
||||
parent({ parent_id }, _, { loaders: { Comments } }) {
|
||||
parent(
|
||||
{ parent_id },
|
||||
_,
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
if (parent_id == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Comments.get.load(parent_id);
|
||||
},
|
||||
user({ author_id }, _, { loaders: { Users } }) {
|
||||
user(
|
||||
{ author_id },
|
||||
_,
|
||||
{
|
||||
loaders: { Users },
|
||||
}
|
||||
) {
|
||||
if (author_id) {
|
||||
return Users.getByID.load(author_id);
|
||||
}
|
||||
},
|
||||
replies({ id, asset_id, reply_count }, { query }, { loaders: { Comments } }) {
|
||||
replies(
|
||||
{ id, asset_id, reply_count },
|
||||
{ query },
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
// Don't bother looking up replies if there aren't any there!
|
||||
if (reply_count === 0) {
|
||||
return {
|
||||
@@ -44,17 +62,35 @@ const Comment = {
|
||||
return Comments.getByQuery(query);
|
||||
},
|
||||
replyCount: property('reply_count'),
|
||||
actions({ id }, _, { loaders: { Actions } }) {
|
||||
actions(
|
||||
{ id },
|
||||
_,
|
||||
{
|
||||
loaders: { Actions },
|
||||
}
|
||||
) {
|
||||
return Actions.getByID.load(id);
|
||||
},
|
||||
action_summaries(comment, _, { loaders: { Actions } }) {
|
||||
action_summaries(
|
||||
comment,
|
||||
_,
|
||||
{
|
||||
loaders: { Actions },
|
||||
}
|
||||
) {
|
||||
if (comment.action_summaries) {
|
||||
return comment.action_summaries;
|
||||
}
|
||||
|
||||
return Actions.getSummariesByItem.load(comment);
|
||||
},
|
||||
asset({ asset_id }, _, { loaders: { Assets } }) {
|
||||
asset(
|
||||
{ asset_id },
|
||||
_,
|
||||
{
|
||||
loaders: { Assets },
|
||||
}
|
||||
) {
|
||||
return Assets.getByID.load(asset_id);
|
||||
},
|
||||
editing: async (comment, _, { loaders: { Settings } }) => {
|
||||
@@ -71,7 +107,13 @@ const Comment = {
|
||||
editableUntil: editableUntil,
|
||||
};
|
||||
},
|
||||
async url(comment, args, { loaders: { Assets } }) {
|
||||
async url(
|
||||
comment,
|
||||
args,
|
||||
{
|
||||
loaders: { Assets },
|
||||
}
|
||||
) {
|
||||
const asset = await Assets.getByID.load(comment.asset_id);
|
||||
if (!asset) {
|
||||
return null;
|
||||
|
||||
@@ -6,17 +6,36 @@ const {
|
||||
} = require('../../perms/constants');
|
||||
|
||||
const RootQuery = {
|
||||
assets(_, { query }, { loaders: { Assets } }) {
|
||||
assets(
|
||||
_,
|
||||
{ query },
|
||||
{
|
||||
loaders: { Assets },
|
||||
}
|
||||
) {
|
||||
return Assets.getByQuery(query);
|
||||
},
|
||||
asset(_, query, { loaders: { Assets } }) {
|
||||
asset(
|
||||
_,
|
||||
query,
|
||||
{
|
||||
loaders: { Assets },
|
||||
}
|
||||
) {
|
||||
if (query.id) {
|
||||
return Assets.getByID.load(query.id);
|
||||
}
|
||||
|
||||
return Assets.getByURL(query.url);
|
||||
},
|
||||
settings(_, args, { loaders: { Settings } }, info) {
|
||||
settings(
|
||||
_,
|
||||
args,
|
||||
{
|
||||
loaders: { Settings },
|
||||
},
|
||||
info
|
||||
) {
|
||||
// Get the fields we want from the settings.
|
||||
const fields = getRequestedFields(info);
|
||||
|
||||
@@ -26,15 +45,33 @@ const RootQuery = {
|
||||
|
||||
// This endpoint is used for loading moderation queues, so hide it in the
|
||||
// event that we aren't an admin.
|
||||
async comments(_, { query }, { loaders: { Comments } }) {
|
||||
async comments(
|
||||
_,
|
||||
{ query },
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
return Comments.getByQuery(query);
|
||||
},
|
||||
|
||||
comment(_, { id }, { loaders: { Comments } }) {
|
||||
comment(
|
||||
_,
|
||||
{ id },
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
return Comments.get.load(id);
|
||||
},
|
||||
|
||||
async commentCount(_, { query }, { loaders: { Comments, Assets } }) {
|
||||
async commentCount(
|
||||
_,
|
||||
{ query },
|
||||
{
|
||||
loaders: { Comments, Assets },
|
||||
}
|
||||
) {
|
||||
const { asset_url, asset_id } = query;
|
||||
if (
|
||||
(!asset_id || asset_id.length === 0) &&
|
||||
@@ -50,7 +87,13 @@ const RootQuery = {
|
||||
return Comments.getCountByQuery(query);
|
||||
},
|
||||
|
||||
async userCount(_, { query }, { loaders: { Users } }) {
|
||||
async userCount(
|
||||
_,
|
||||
{ query },
|
||||
{
|
||||
loaders: { Users },
|
||||
}
|
||||
) {
|
||||
return Users.getCountByQuery(query);
|
||||
},
|
||||
|
||||
@@ -65,13 +108,25 @@ const RootQuery = {
|
||||
},
|
||||
|
||||
// this returns an arbitrary user
|
||||
user(_, { id }, { loaders: { Users } }) {
|
||||
user(
|
||||
_,
|
||||
{ id },
|
||||
{
|
||||
loaders: { Users },
|
||||
}
|
||||
) {
|
||||
return Users.getByID.load(id);
|
||||
},
|
||||
|
||||
// This endpoint is used for loading the user moderation queues (users whose username has been flagged),
|
||||
// so hide it in the event that we aren't an admin.
|
||||
users(_, { query }, { loaders: { Users } }) {
|
||||
users(
|
||||
_,
|
||||
{ query },
|
||||
{
|
||||
loaders: { Users },
|
||||
}
|
||||
) {
|
||||
return Users.getByQuery(query);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,7 +5,13 @@ const Settings = {
|
||||
karmaThresholds: (
|
||||
settings,
|
||||
args,
|
||||
{ connectors: { services: { Karma: { THRESHOLDS } } } }
|
||||
{
|
||||
connectors: {
|
||||
services: {
|
||||
Karma: { THRESHOLDS },
|
||||
},
|
||||
},
|
||||
}
|
||||
) => THRESHOLDS,
|
||||
};
|
||||
|
||||
|
||||
+28
-4
@@ -16,20 +16,44 @@ const {
|
||||
const { property } = require('lodash');
|
||||
|
||||
const User = {
|
||||
action_summaries(user, _, { loaders: { Actions } }) {
|
||||
action_summaries(
|
||||
user,
|
||||
_,
|
||||
{
|
||||
loaders: { Actions },
|
||||
}
|
||||
) {
|
||||
return Actions.getSummariesByItem.load(user);
|
||||
},
|
||||
actions({ id }, _, { loaders: { Actions } }) {
|
||||
actions(
|
||||
{ id },
|
||||
_,
|
||||
{
|
||||
loaders: { Actions },
|
||||
}
|
||||
) {
|
||||
return Actions.getByID.load(id);
|
||||
},
|
||||
comments({ id }, { query }, { loaders: { Comments } }) {
|
||||
comments(
|
||||
{ id },
|
||||
{ query },
|
||||
{
|
||||
loaders: { Comments },
|
||||
}
|
||||
) {
|
||||
// Set the author id on the query.
|
||||
query.author_id = id;
|
||||
|
||||
return Comments.getByQuery(query);
|
||||
},
|
||||
|
||||
ignoredUsers({ ignoresUsers }, args, { loaders: { Users } }) {
|
||||
ignoredUsers(
|
||||
{ ignoresUsers },
|
||||
args,
|
||||
{
|
||||
loaders: { Users },
|
||||
}
|
||||
) {
|
||||
// Return nothing if there is nothing to query for.
|
||||
if (!ignoresUsers || ignoresUsers.length <= 0) {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user