Set notifications.createdAt only at creation

- we should not be setting it every time a notification is created
This commit is contained in:
mattwr18 2019-09-13 17:15:50 +02:00
parent 2a3e6ad76f
commit ce487f1e0f
3 changed files with 15 additions and 11 deletions

View File

@ -27,7 +27,10 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
MERGE (post)-[notification:NOTIFIED {reason: $reason}]->(user)
SET notification.read = FALSE
SET notification.updatedAt = toString(datetime())
SET notification.createdAt = toString(datetime())
SET (
CASE
WHEN notification.createdAt IS NULL
THEN notification END ).createdAt = toString(datetime())
`
break
}
@ -41,7 +44,10 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
SET notification.read = FALSE
SET notification.updatedAt = toString(datetime())
SET notification.createdAt = toString(datetime())
SET (
CASE
WHEN notification.createdAt IS NULL
THEN notification END ).createdAt = toString(datetime())
`
break
}
@ -55,7 +61,10 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user)
SET notification.read = FALSE
SET notification.updatedAt = toString(datetime())
SET notification.createdAt = toString(datetime())
SET (
CASE
WHEN notification.createdAt IS NULL
THEN notification END ).createdAt = toString(datetime())
`
break
}

View File

@ -391,7 +391,7 @@ describe('notifications', () => {
expect(Date.parse(createdAtBefore)).toEqual(expect.any(Number))
expect(createdAtAfter).toBeTruthy()
expect(Date.parse(createdAtAfter)).toEqual(expect.any(Number))
expect(createdAtBefore).not.toEqual(createdAtAfter)
expect(createdAtBefore).toEqual(createdAtAfter)
})
})
})

View File

@ -21,7 +21,7 @@ export default {
SET comment.createdAt = toString(datetime())
SET comment.updatedAt = toString(datetime())
MERGE (post)<-[:COMMENTS]-(comment)<-[:WROTE]-(author)
RETURN comment, author
RETURN comment
`
const transactionRes = await session.run(createCommentCypher, {
userId: context.user.id,
@ -30,12 +30,7 @@ export default {
})
session.close()
const [response] = transactionRes.records.map(record => {
return {
...record.get('comment').properties,
author: record.get('author').properties,
}
})
const [response] = transactionRes.records.map(record => record.get('comment').properties)
return response
},