mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
31 lines
824 B
JavaScript
31 lines
824 B
JavaScript
import extractIds from './extractIds'
|
|
|
|
const notify = async (resolve, root, args, context, resolveInfo) => {
|
|
// extract user ids before xss-middleware removes link classes
|
|
const ids = extractIds(args.content)
|
|
|
|
const post = await resolve(root, args, context, resolveInfo)
|
|
|
|
const session = context.driver.session()
|
|
const { id: postId } = post
|
|
const createdAt = (new Date()).toISOString()
|
|
const cypher = `
|
|
match(u:User) where u.id in $ids
|
|
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, { ids, createdAt, postId })
|
|
session.close()
|
|
|
|
return post
|
|
}
|
|
|
|
export default {
|
|
Mutation: {
|
|
CreatePost: notify,
|
|
UpdatePost: notify
|
|
}
|
|
}
|