Implement block+unblock basic features

This commit is contained in:
Robert Schäfer 2019-08-07 17:27:53 +02:00 committed by roschaefer
parent 700bdcb8f1
commit 293054a05b
2 changed files with 11 additions and 3 deletions

View File

@ -38,9 +38,17 @@ export default {
},
Mutation: {
block: async (object, args, context, resolveInfo) => {
if (context.user.id === args.id) return null
const { user: currentUser } = context
if (currentUser.id === args.id) return null
await instance.cypher(
`
MATCH(u:User {id: $currentUser.id})-[r:FOLLOWS]->(b:User {id: $args.id})
DELETE r
`,
{ currentUser, args },
)
const [user, blockedUser] = await Promise.all([
instance.find('User', context.user.id),
instance.find('User', currentUser.id),
instance.find('User', args.id),
])
await user.relateTo(blockedUser, 'blocked')

View File

@ -44,7 +44,7 @@ type User {
)
isBlocked: Boolean! @cypher(
statement: """
MATCH (this)-[:BLOCKED]->(u:User {id: $cypherParams.currentUserId})
MATCH (this)<-[:BLOCKED]-(u:User {id: $cypherParams.currentUserId})
RETURN COUNT(u) >= 1
"""
)