1
1
import { forwardRef , Inject , Injectable } from '@nestjs/common' ;
2
2
import { Nil } from '@seedcompany/common' ;
3
- import { inArray , node , Query , relation } from 'cypher-query-builder' ;
3
+ import {
4
+ inArray ,
5
+ isNull ,
6
+ node ,
7
+ not ,
8
+ Query ,
9
+ relation ,
10
+ } from 'cypher-query-builder' ;
4
11
import { omit } from 'lodash' ;
5
12
import { DateTime } from 'luxon' ;
6
13
import {
@@ -14,7 +21,6 @@ import {
14
21
import { CommonRepository } from '~/core/database' ;
15
22
import {
16
23
apoc ,
17
- coalesce ,
18
24
createRelationships ,
19
25
filter ,
20
26
merge ,
@@ -77,7 +83,7 @@ export class NotificationRepository extends CommonRepository {
77
83
)
78
84
. create ( [
79
85
node ( 'node' ) ,
80
- relation ( 'out' , '' , 'recipient' , { unread : variable ( 'true' ) } ) ,
86
+ relation ( 'out' , '' , 'recipient' ) ,
81
87
node ( 'recipient' ) ,
82
88
] )
83
89
. return < { totalRecipients : number } > (
@@ -98,7 +104,7 @@ export class NotificationRepository extends CommonRepository {
98
104
relation ( 'out' , 'recipient' , 'recipient' ) ,
99
105
requestingUser ( session ) ,
100
106
] )
101
- . setValues ( { recipient : { unread } } , true )
107
+ . setValues ( { ' recipient.readAt' : unread ? null : DateTime . now ( ) } )
102
108
. with ( 'node' )
103
109
. apply ( this . hydrate ( session ) )
104
110
. first ( ) ;
@@ -128,9 +134,10 @@ export class NotificationRepository extends CommonRepository {
128
134
q
129
135
. match ( [
130
136
node ( 'node' , 'Notification' ) ,
131
- relation ( 'out' , '' , 'recipient' , { unread : variable ( 'true' ) } ) ,
137
+ relation ( 'out' , 'recipient ' , 'recipient' ) ,
132
138
node ( 'requestingUser' ) ,
133
139
] )
140
+ . where ( { 'recipient.readAt' : isNull ( ) } )
134
141
. return < { totalUnread : number } > ( 'count(node) as totalUnread' ) ,
135
142
)
136
143
. return ( [ 'items' , 'hasMore' , 'total' , 'totalUnread' ] )
@@ -168,7 +175,8 @@ export class NotificationRepository extends CommonRepository {
168
175
. return < { dto : UnsecuredDto < Notification > } > (
169
176
merge ( 'node' , 'extra' , {
170
177
__typename : 'node.type + "Notification"' ,
171
- unread : coalesce ( 'recipient.unread' , false ) ,
178
+ unread : 'recipient.readAt is null' ,
179
+ readAt : 'recipient.readAt' ,
172
180
} ) . as ( 'dto' ) ,
173
181
) ;
174
182
}
@@ -179,5 +187,7 @@ export class NotificationRepository extends CommonRepository {
179
187
}
180
188
181
189
const notificationFilters = filter . define ( ( ) => NotificationFilters , {
182
- unread : ( { value } ) => ( { recipient : { unread : value } } ) ,
190
+ unread : ( { value } ) => ( {
191
+ 'recipient.readAt' : value ? isNull ( ) : not ( isNull ( ) ) ,
192
+ } ) ,
183
193
} ) ;
0 commit comments