mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-16 09:54:41 +00:00
Test driven approach to implement notification of report filing user 3
This commit is contained in:
parent
4da67d3bc8
commit
e5718fe0ea
@ -1,6 +1,8 @@
|
||||
import extractMentionedUsers from './mentions/extractMentionedUsers'
|
||||
import { validateNotifyUsers } from '../validation/validationMiddleware'
|
||||
|
||||
const debug = require('debug')('backend:notificationsMiddleware')
|
||||
|
||||
const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo) => {
|
||||
const idsOfUsers = extractMentionedUsers(args.content)
|
||||
const post = await resolve(root, args, context, resolveInfo)
|
||||
@ -36,6 +38,8 @@ const postAuthorOfComment = async (commentId, { context }) => {
|
||||
)
|
||||
})
|
||||
return postAuthorId.records.map(record => record.get('authorId'))
|
||||
} catch (error) {
|
||||
debug(error)
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
@ -77,6 +81,8 @@ const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => {
|
||||
await session.writeTransaction(transaction => {
|
||||
return transaction.run(mentionedCypher, { id, idsOfUsers, reason })
|
||||
})
|
||||
} catch (error) {
|
||||
debug(error)
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
@ -100,6 +106,8 @@ const notifyUsersOfComment = async (label, commentId, postAuthorId, reason, cont
|
||||
{ commentId, postAuthorId, reason },
|
||||
)
|
||||
})
|
||||
} catch (error) {
|
||||
debug(error)
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
@ -123,7 +131,7 @@ const notifyReportFiler = async (resolve, root, args, context, resolveInfo) => {
|
||||
try {
|
||||
await session.writeTransaction(async transaction => {
|
||||
await transaction.run(
|
||||
`
|
||||
/* Wolle`
|
||||
MATCH (resource {id: $resourceId})<-[:BELONGS_TO]-(:Report {id: $reportId})<-[:FILED]-(submitter:User {id: $submitterId})
|
||||
WHERE resource: User OR resource: Post OR resource: Comment
|
||||
// Wolle MERGE (resource)-[notification:NOTIFIED {reason: $reason, reportId: $reportId}]->(submitter)
|
||||
@ -131,6 +139,15 @@ const notifyReportFiler = async (resolve, root, args, context, resolveInfo) => {
|
||||
ON CREATE SET notification.createdAt = toString(datetime()), notification.updatedAt = notification.createdAt
|
||||
ON MATCH SET notification.updatedAt = toString(datetime())
|
||||
SET notification.read = FALSE
|
||||
`,*/
|
||||
`
|
||||
MATCH (resource {id: $resourceId})<-[:BELONGS_TO]-(report:Report {id: $reportId})<-[:FILED]-(submitter:User {id: $submitterId})
|
||||
WHERE resource: User OR resource: Post OR resource: Comment
|
||||
// Wolle MERGE (resource)-[notification:NOTIFIED {reason: $reason, reportId: $reportId}]->(submitter)
|
||||
MERGE (report)-[notification:NOTIFIED {reason: $reason}]->(submitter)
|
||||
ON CREATE SET notification.createdAt = toString(datetime()), notification.updatedAt = notification.createdAt
|
||||
ON MATCH SET notification.updatedAt = toString(datetime())
|
||||
SET notification.read = FALSE
|
||||
`,
|
||||
{
|
||||
reportId,
|
||||
@ -143,7 +160,9 @@ const notifyReportFiler = async (resolve, root, args, context, resolveInfo) => {
|
||||
)
|
||||
console.log('success !!!')
|
||||
})
|
||||
} finally {
|
||||
} catch (error) {
|
||||
debug(error)
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ export default {
|
||||
const notificationsTransactionResponse = await transaction.run(
|
||||
`
|
||||
MATCH (resource {deleted: false, disabled: false})-[notification:NOTIFIED]->(user:User {id:$id})
|
||||
WHERE (labels(resource)[0] in [Post, Comment] AND NOT resource.deleted AND NOT resource.disabled) OR labels(resource)[0] in [Report]
|
||||
${whereClause}
|
||||
WITH user, notification, resource,
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*}] as authors,
|
||||
|
||||
@ -8,7 +8,7 @@ type NOTIFIED {
|
||||
reason: NotificationReason
|
||||
}
|
||||
|
||||
union NotificationSource = Post | Comment
|
||||
union NotificationSource = Post | Comment | Report
|
||||
|
||||
enum NotificationOrdering {
|
||||
createdAt_asc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user