mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Start refactoring follow
This commit is contained in:
parent
c513b7ba2e
commit
587025e4d3
@ -1,49 +1,49 @@
|
|||||||
|
import gql from 'graphql-tag'
|
||||||
|
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Mutation: {
|
Mutation: {
|
||||||
follow: async (_object, params, context, _resolveInfo) => {
|
follow: async (object, params, context, resolveInfo) => {
|
||||||
|
const result = await neo4jgraphql(object, params, context, resolveInfo, true)
|
||||||
const { followedId, followedType } = params
|
const { followedId, followedType } = params
|
||||||
const session = context.driver.session()
|
|
||||||
|
|
||||||
let sessionRes = await session.run(
|
const session = context.driver.session()
|
||||||
`MATCH (n {id: $id}), (u:User {id: $cypherParams.currentUserId})
|
await session.run(
|
||||||
WHERE $type IN labels(n) AND NOT $id = $cypherParams.currentUserId
|
gql`
|
||||||
|
MATCH (n {id: $followedId}), (u:User {id: $userId})
|
||||||
|
WHERE $type IN labels(n) AND NOT $id = $userId
|
||||||
MERGE (u)-[r:FOLLOWS]->(n)
|
MERGE (u)-[r:FOLLOWS]->(n)
|
||||||
RETURN COUNT(r) > 0`,
|
RETURN COUNT(r) > 0`,
|
||||||
{
|
{
|
||||||
badgeId: fromBadgeId,
|
followedId: followedId,
|
||||||
rewardedUserId: toUserId
|
type: followedType,
|
||||||
|
userId: context.user.id
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const [rewardedUser] = sessionRes.records.map(record => {
|
|
||||||
return record.get('rewardedUser')
|
|
||||||
})
|
|
||||||
|
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
return rewardedUser.id
|
return result
|
||||||
},
|
|
||||||
|
|
||||||
unfollow: async (_object, params, context, _resolveInfo) => {
|
|
||||||
const { fromBadgeId, toUserId } = params
|
|
||||||
const session = context.driver.session()
|
|
||||||
|
|
||||||
let sessionRes = await session.run(
|
|
||||||
`MATCH (badge:Badge {id: $badgeId})-[reward:REWARDED]->(rewardedUser:User {id: $rewardedUserId})
|
|
||||||
DELETE reward
|
|
||||||
RETURN rewardedUser {.id}`,
|
|
||||||
{
|
|
||||||
badgeId: fromBadgeId,
|
|
||||||
rewardedUserId: toUserId
|
|
||||||
}
|
|
||||||
)
|
|
||||||
const [rewardedUser] = sessionRes.records.map(record => {
|
|
||||||
return record.get('rewardedUser')
|
|
||||||
})
|
|
||||||
session.close()
|
|
||||||
|
|
||||||
return rewardedUser.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unfollow: async (_object, params, context, _resolveInfo) => {
|
||||||
|
// const { fromBadgeId, toUserId } = params
|
||||||
|
// const session = context.driver.session()
|
||||||
|
|
||||||
|
// let sessionRes = await session.run(
|
||||||
|
// `MATCH (badge:Badge {id: $badgeId})-[reward:REWARDED]->(rewardedUser:User {id: $rewardedUserId})
|
||||||
|
// DELETE reward
|
||||||
|
// RETURN rewardedUser {.id}`,
|
||||||
|
// {
|
||||||
|
// badgeId: fromBadgeId,
|
||||||
|
// rewardedUserId: toUserId
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
// const [rewardedUser] = sessionRes.records.map(record => {
|
||||||
|
// return record.get('rewardedUser')
|
||||||
|
// })
|
||||||
|
// session.close()
|
||||||
|
|
||||||
|
// return rewardedUser.id
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -42,12 +42,7 @@ type Mutation {
|
|||||||
RETURN COUNT(r) > 0
|
RETURN COUNT(r) > 0
|
||||||
""")
|
""")
|
||||||
"Follow the given Type and ID"
|
"Follow the given Type and ID"
|
||||||
follow(id: ID!, type: FollowTypeEnum): Boolean! @cypher(statement: """
|
follow(id: ID!, type: FollowTypeEnum): Boolean!
|
||||||
MATCH (n {id: $id}), (u:User {id: $cypherParams.currentUserId})
|
|
||||||
WHERE $type IN labels(n) AND NOT $id = $cypherParams.currentUserId
|
|
||||||
MERGE (u)-[r:FOLLOWS]->(n)
|
|
||||||
RETURN COUNT(r) > 0
|
|
||||||
""")
|
|
||||||
"Unfollow the given Type and ID"
|
"Unfollow the given Type and ID"
|
||||||
unfollow(id: ID!, type: FollowTypeEnum): Boolean! @cypher(statement: """
|
unfollow(id: ID!, type: FollowTypeEnum): Boolean! @cypher(statement: """
|
||||||
MATCH (:User {id: $cypherParams.currentUserId})-[r:FOLLOWS]->(n {id: $id})
|
MATCH (:User {id: $cypherParams.currentUserId})-[r:FOLLOWS]->(n {id: $id})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user