mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Added file "backend/src/resolvers/follow.js"
WIP !!! In development! Not able to run now!
This commit is contained in:
parent
262655a1d8
commit
97707f7a20
49
backend/src/resolvers/follow.js
Normal file
49
backend/src/resolvers/follow.js
Normal file
@ -0,0 +1,49 @@
|
||||
export default {
|
||||
Mutation: {
|
||||
follow: async (_object, params, context, _resolveInfo) => {
|
||||
const { followedId, followedType } = params
|
||||
const session = context.driver.session()
|
||||
|
||||
let sessionRes = await session.run(
|
||||
`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`,
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user