mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Keep existing filter params + same for text search
This commit is contained in:
parent
5fb60d1132
commit
8de0195cf8
@ -2,19 +2,36 @@ import uuid from 'uuid/v4'
|
|||||||
import { neo4jgraphql } from 'neo4j-graphql-js'
|
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||||
import fileUpload from './fileUpload'
|
import fileUpload from './fileUpload'
|
||||||
import { getBlockedUsers, getBlockedByUsers } from './users.js'
|
import { getBlockedUsers, getBlockedByUsers } from './users.js'
|
||||||
|
import { mergeWith, isArray } from 'lodash'
|
||||||
|
|
||||||
|
const filterForBlockedUsers = async (params, context) => {
|
||||||
|
const [blockedUsers, blockedByUsers] = await Promise.all([
|
||||||
|
getBlockedUsers(context),
|
||||||
|
getBlockedByUsers(context),
|
||||||
|
])
|
||||||
|
const badIds = [...blockedByUsers.map(b => b.id), ...blockedUsers.map(b => b.id)]
|
||||||
|
params.filter = mergeWith(
|
||||||
|
params.filter,
|
||||||
|
{
|
||||||
|
author_not: { id_in: badIds },
|
||||||
|
},
|
||||||
|
(objValue, srcValue) => {
|
||||||
|
if (isArray(objValue)) {
|
||||||
|
return objValue.concat(srcValue)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
Post: async (object, params, context, resolveInfo) => {
|
Post: async (object, params, context, resolveInfo) => {
|
||||||
const blockedUsers = await getBlockedUsers(context)
|
params = await filterForBlockedUsers(params, context)
|
||||||
const blockedByUsers = await getBlockedByUsers(context)
|
return neo4jgraphql(object, params, context, resolveInfo, false)
|
||||||
params.filter = {
|
},
|
||||||
author_not: { id_in: [
|
findPosts: async (object, params, context, resolveInfo) => {
|
||||||
...blockedByUsers.map(b => b.id),
|
params = await filterForBlockedUsers(params, context)
|
||||||
...blockedUsers.map(b => b.id),
|
|
||||||
] }
|
|
||||||
}
|
|
||||||
|
|
||||||
return neo4jgraphql(object, params, context, resolveInfo, false)
|
return neo4jgraphql(object, params, context, resolveInfo, false)
|
||||||
},
|
},
|
||||||
PostsEmotionsCountByEmotion: async (object, params, context, resolveInfo) => {
|
PostsEmotionsCountByEmotion: async (object, params, context, resolveInfo) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user