Test driven approach to implement notification of report filing user 3

This commit is contained in:
Wolfgang Huß 2019-12-18 15:28:25 +01:00
parent 4da67d3bc8
commit e5718fe0ea
3 changed files with 23 additions and 3 deletions

View File

@ -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()
}
}

View File

@ -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,

View File

@ -8,7 +8,7 @@ type NOTIFIED {
reason: NotificationReason
}
union NotificationSource = Post | Comment
union NotificationSource = Post | Comment | Report
enum NotificationOrdering {
createdAt_asc