mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
fix block user (#8363)
This commit is contained in:
parent
caeff070b7
commit
fa0280f9e9
@ -113,32 +113,53 @@ export default {
|
|||||||
blockUser: async (object, args, context, resolveInfo) => {
|
blockUser: async (object, args, context, resolveInfo) => {
|
||||||
const { user: currentUser } = context
|
const { user: currentUser } = context
|
||||||
if (currentUser.id === args.id) return null
|
if (currentUser.id === args.id) return null
|
||||||
await neode.cypher(
|
|
||||||
`
|
const session = context.driver.session()
|
||||||
MATCH(u:User {id: $currentUser.id})-[r:FOLLOWS]->(b:User {id: $args.id})
|
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||||
DELETE r
|
const unBlockUserTransactionResponse = await transaction.run(
|
||||||
`,
|
`
|
||||||
{ currentUser, args },
|
MATCH (blockedUser:User {id: $args.id})
|
||||||
)
|
MATCH (currentUser:User {id: $currentUser.id})
|
||||||
const [user, blockedUser] = await Promise.all([
|
OPTIONAL MATCH (currentUser)-[r:FOLLOWS]->(blockedUser)
|
||||||
neode.find('User', currentUser.id),
|
DELETE r
|
||||||
neode.find('User', args.id),
|
CREATE (currentUser)-[:BLOCKED]->(blockedUser)
|
||||||
])
|
RETURN blockedUser {.*}
|
||||||
await user.relateTo(blockedUser, 'blocked')
|
`,
|
||||||
return blockedUser.toJson()
|
{ currentUser, args },
|
||||||
|
)
|
||||||
|
return unBlockUserTransactionResponse.records.map((record) => record.get('blockedUser'))[0]
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
return await writeTxResultPromise
|
||||||
|
} catch (error) {
|
||||||
|
throw new UserInputError(error.message)
|
||||||
|
} finally {
|
||||||
|
session.close()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
unblockUser: async (object, args, context, resolveInfo) => {
|
unblockUser: async (object, args, context, resolveInfo) => {
|
||||||
const { user: currentUser } = context
|
const { user: currentUser } = context
|
||||||
if (currentUser.id === args.id) return null
|
if (currentUser.id === args.id) return null
|
||||||
await neode.cypher(
|
|
||||||
`
|
const session = context.driver.session()
|
||||||
MATCH(u:User {id: $currentUser.id})-[r:BLOCKED]->(b:User {id: $args.id})
|
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||||
DELETE r
|
const unBlockUserTransactionResponse = await transaction.run(
|
||||||
`,
|
`
|
||||||
{ currentUser, args },
|
MATCH(u:User {id: $currentUser.id})-[r:BLOCKED]->(blockedUser:User {id: $args.id})
|
||||||
)
|
DELETE r
|
||||||
const blockedUser = await neode.find('User', args.id)
|
RETURN blockedUser {.*}
|
||||||
return blockedUser.toJson()
|
`,
|
||||||
|
{ currentUser, args },
|
||||||
|
)
|
||||||
|
return unBlockUserTransactionResponse.records.map((record) => record.get('blockedUser'))[0]
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
return await writeTxResultPromise
|
||||||
|
} catch (error) {
|
||||||
|
throw new UserInputError(error.message)
|
||||||
|
} finally {
|
||||||
|
session.close()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
UpdateUser: async (_parent, params, context, _resolveInfo) => {
|
UpdateUser: async (_parent, params, context, _resolveInfo) => {
|
||||||
const { avatar: avatarInput } = params
|
const { avatar: avatarInput } = params
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user