File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
22
22
import { v7 } from "uuid" ;
23
23
import { fromUUID , typeid } from "typeid-js" ;
24
24
import { Region } from "../../../enums/Region" ;
25
+ import { sendNotifications } from "../../../libs/push-gateway" ;
25
26
26
27
interface ZapUploadInfo {
27
28
zapId : string ;
@@ -121,6 +122,54 @@ export class ZapController extends Controller {
121
122
uploaded : true
122
123
}
123
124
} ) ;
125
+
126
+ const friends = await prisma . user . findMany ( {
127
+ where : {
128
+ deviceToken : {
129
+ not : null
130
+ } ,
131
+ OR : [
132
+ {
133
+ friendsWith : {
134
+ some : {
135
+ receiverId : request . user . user . id
136
+ }
137
+ } ,
138
+ friendsOf : {
139
+ some : {
140
+ senderId : request . user . user . id
141
+ }
142
+ }
143
+ }
144
+ ]
145
+ }
146
+ } ) ;
147
+
148
+ const notifications = friends . map (
149
+ ( friend ) =>
150
+ ( {
151
+ id : typeid ( Prefix . NOTIFICATION ) . toString ( ) ,
152
+ userId : friend . id ,
153
+ type : "NEW_DAILY_ZAP" ,
154
+ title : "New Zap" ,
155
+ content : `${ request . user . user . firstName } has uploaded a new Zap!` ,
156
+ targetId : id ,
157
+ deviceToken : friend . deviceToken !
158
+ } as const )
159
+ ) ;
160
+
161
+ await prisma . notification . createMany ( {
162
+ data : notifications
163
+ } ) ;
164
+
165
+ await sendNotifications ( {
166
+ body : {
167
+ notifications : notifications . map ( ( notification ) => ( {
168
+ notificationId : notification . id ,
169
+ deviceToken : notification . deviceToken
170
+ } ) )
171
+ }
172
+ } ) ;
124
173
}
125
174
126
175
@Post ( "{id}/repost" )
You can’t perform that action at this time.
0 commit comments