Follow @Tirokk's suggestion

This commit is contained in:
roschaefer 2019-08-30 12:46:36 +02:00
parent c29ee5e3d3
commit cbcba8f08d
8 changed files with 16 additions and 16 deletions

View File

@ -4,13 +4,13 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
if (!idsOfUsers.length) return
// Checked here, because it does not go through GraphQL checks at all in this file.
const reasonsAllowed = ['mentioned_in_post', 'mentioned_in_comment', 'comment_on_post']
const reasonsAllowed = ['mentioned_in_post', 'mentioned_in_comment', 'commented_on_post']
if (!reasonsAllowed.includes(reason)) {
throw new Error('Notification reason is not allowed!')
}
if (
(label === 'Post' && reason !== 'mentioned_in_post') ||
(label === 'Comment' && !['mentioned_in_comment', 'comment_on_post'].includes(reason))
(label === 'Comment' && !['mentioned_in_comment', 'commented_on_post'].includes(reason))
) {
throw new Error('Notification does not fit the reason!')
}
@ -44,7 +44,7 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
`
break
}
case 'comment_on_post': {
case 'commented_on_post': {
cypher = `
MATCH (postAuthor: User)-[:WROTE]->(post: Post)<-[:COMMENTS]-(comment: Comment { id: $id })<-[:WROTE]-(author: User)
MATCH (user: User)
@ -108,7 +108,7 @@ const handleCreateComment = async (resolve, root, args, context, resolveInfo) =>
return record.get('user')
})
if (context.user.id !== postAuthor.id) {
await notifyUsers('Comment', comment.id, [postAuthor.id], 'comment_on_post', context)
await notifyUsers('Comment', comment.id, [postAuthor.id], 'commented_on_post', context)
}
}

View File

@ -162,7 +162,7 @@ describe('notifications', () => {
{
read: false,
createdAt: expect.any(String),
reason: 'comment_on_post',
reason: 'commented_on_post',
from: {
__typename: 'Comment',
id: 'c47',

View File

@ -16,7 +16,7 @@ const transformReturnType = record => {
export default {
Query: {
notifications: async (parent, args, context, resolveInfo) => {
const { user } = context
const { user: currentUser } = context
const session = context.driver.session()
let notifications
let whereClause
@ -49,7 +49,7 @@ export default {
RETURN resource, notification, user
${orderByClause}
`
const result = await session.run(cypher, { id: user.id })
const result = await session.run(cypher, { id: currentUser.id })
notifications = await result.records.map(transformReturnType)
} finally {
session.close()
@ -59,7 +59,7 @@ export default {
},
Mutation: {
markAsRead: async (parent, args, context, resolveInfo) => {
const { user } = context
const { user: currentUser } = context
const session = context.driver.session()
let notification
try {
@ -68,7 +68,7 @@ export default {
SET notification.read = TRUE
RETURN resource, notification, user
`
const result = await session.run(cypher, { resourceId: args.id, id: user.id })
const result = await session.run(cypher, { resourceId: args.id, id: currentUser.id })
const notifications = await result.records.map(transformReturnType)
notification = notifications[0]
} finally {

View File

@ -1,5 +1,5 @@
enum ReasonNotification {
mentioned_in_post
mentioned_in_comment
comment_on_post
}
commented_on_post
}

View File

@ -16,7 +16,7 @@ enum NotificationOrdering {
enum NotificationReason {
mentioned_in_post
mentioned_in_comment
comment_on_post
commented_on_post
}
type Query {

View File

@ -37,7 +37,7 @@ describe('Notification', () => {
describe('given a notification about a comment on a post', () => {
beforeEach(() => {
propsData.notification = {
reason: 'comment_on_post',
reason: 'commented_on_post',
from: {
__typename: 'Comment',
id: 'comment-1',
@ -56,7 +56,7 @@ describe('Notification', () => {
it('renders reason', () => {
wrapper = Wrapper()
expect(wrapper.find('.reason-text-for-test').text()).toEqual(
'notifications.menu.comment_on_post',
'notifications.menu.commented_on_post',
)
})
it('renders title', () => {

View File

@ -134,7 +134,7 @@
"menu": {
"mentioned_in_post": "Hat dich in einem Beitrag erwähnt …",
"mentioned_in_comment": "Hat dich in einem Kommentar erwähnt …",
"comment_on_post": "Hat deinen Beitrag kommentiert …"
"commented_on_post": "Hat deinen Beitrag kommentiert …"
}
},
"search": {

View File

@ -134,7 +134,7 @@
"menu": {
"mentioned_in_post": "Mentioned you in a post …",
"mentioned_in_comment": "Mentioned you in a comment …",
"comment_on_post": "Commented on your post …"
"commented_on_post": "Commented on your post …"
}
},
"search": {