mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
28 lines
752 B
JavaScript
28 lines
752 B
JavaScript
import { extractSlugs } from './mentions'
|
|
|
|
const notify = async (resolve, root, args, context, resolveInfo) => {
|
|
const post = await resolve(root, args, context, resolveInfo)
|
|
|
|
const session = context.driver.session()
|
|
const { content, id: postId } = post
|
|
const slugs = extractSlugs(content)
|
|
const createdAt = (new Date()).toISOString()
|
|
const cypher = `
|
|
match(u:User) where u.slug in $slugs
|
|
match(p:Post) where p.id = $postId
|
|
create(n:Notification{id: apoc.create.uuid(), read: false, createdAt: $createdAt})
|
|
merge (n)-[:NOTIFIED]->(u)
|
|
merge (p)-[:NOTIFIED]->(n)
|
|
`
|
|
await session.run(cypher, { slugs, createdAt, postId })
|
|
session.close()
|
|
|
|
return post
|
|
}
|
|
|
|
export default {
|
|
Mutation: {
|
|
CreatePost: notify
|
|
}
|
|
}
|