mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
cypher to track user interactions
This commit is contained in:
parent
7bbdd5852f
commit
7c5e5d971e
@ -1,8 +1,38 @@
|
||||
const createRelatedCypher = (relation) => `
|
||||
MATCH (user:User { id: $currentUser})
|
||||
MATCH (post:Post { id: $postId})<-[r:${relation}]-(u:User)
|
||||
WHERE NOT u.disabled AND NOT u.deleted
|
||||
WITH user, post, count(DISTINCT u) AS count
|
||||
MERGE (user)-[relation:${relation} { }]->(post)
|
||||
ON CREATE
|
||||
SET relation.count = 1,
|
||||
relation.createdAt = toString(datetime()),
|
||||
post.clickCount = count + 1
|
||||
ON MATCH
|
||||
SET relation.count = relation.count + 1,
|
||||
relation.updatedAt = toString(datetime()),
|
||||
post.clickCount = count
|
||||
RETURN user, post, relation
|
||||
`
|
||||
|
||||
const setPostCounter = async (postId, relation, context) => {
|
||||
const { user: currentUser } = context
|
||||
const session = context.driver.session()
|
||||
try {
|
||||
await session.writeTransaction((txc) => {
|
||||
return txc.run(
|
||||
createRelatedCypher(relation),
|
||||
{ currentUser, postId },
|
||||
)
|
||||
})
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
}
|
||||
|
||||
const userClickedPost = async (resolve, root, args, context, info) => {
|
||||
if (args.id) {
|
||||
console.log('post clicked--', args.id)
|
||||
await setPostCounter(args.id, 'CLICKED', context)
|
||||
}
|
||||
return resolve(root, args, context, info)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user