@@ -120,10 +120,17 @@ export async function inviteMembers({
120
120
} ) ;
121
121
}
122
122
123
- export async function getInviteFromToken ( { token } : { token : string } ) {
123
+ export async function getInviteFromToken ( { token, userId } : { token : string ; userId : string } ) {
124
124
return await prisma . orgMemberInvite . findFirst ( {
125
125
where : {
126
126
token,
127
+ organization : {
128
+ members : {
129
+ some : {
130
+ userId,
131
+ } ,
132
+ } ,
133
+ } ,
127
134
} ,
128
135
include : {
129
136
organization : true ,
@@ -153,6 +160,13 @@ export async function acceptInvite({ userId, inviteId }: { userId: string; invit
153
160
const invite = await tx . orgMemberInvite . delete ( {
154
161
where : {
155
162
id : inviteId ,
163
+ organization : {
164
+ members : {
165
+ some : {
166
+ userId,
167
+ } ,
168
+ } ,
169
+ } ,
156
170
} ,
157
171
include : {
158
172
organization : {
@@ -188,6 +202,13 @@ export async function acceptInvite({ userId, inviteId }: { userId: string; invit
188
202
const remainingInvites = await tx . orgMemberInvite . findMany ( {
189
203
where : {
190
204
email : invite . email ,
205
+ organization : {
206
+ members : {
207
+ some : {
208
+ userId,
209
+ } ,
210
+ } ,
211
+ } ,
191
212
} ,
192
213
} ) ;
193
214
@@ -201,6 +222,13 @@ export async function declineInvite({ userId, inviteId }: { userId: string; invi
201
222
const declinedInvite = await prisma . orgMemberInvite . delete ( {
202
223
where : {
203
224
id : inviteId ,
225
+ organization : {
226
+ members : {
227
+ some : {
228
+ userId,
229
+ } ,
230
+ } ,
231
+ } ,
204
232
} ,
205
233
include : {
206
234
organization : true ,
@@ -217,17 +245,25 @@ export async function declineInvite({ userId, inviteId }: { userId: string; invi
217
245
const remainingInvites = await prisma . orgMemberInvite . findMany ( {
218
246
where : {
219
247
email : user ! . email ,
248
+ organization : {
249
+ members : {
250
+ some : {
251
+ userId,
252
+ } ,
253
+ } ,
254
+ } ,
220
255
} ,
221
256
} ) ;
222
257
223
258
return { remainingInvites, organization : declinedInvite . organization } ;
224
259
} ) ;
225
260
}
226
261
227
- export async function resendInvite ( { inviteId } : { inviteId : string } ) {
262
+ export async function resendInvite ( { inviteId, userId } : { inviteId : string ; userId : string } ) {
228
263
return await prisma . orgMemberInvite . update ( {
229
264
where : {
230
265
id : inviteId ,
266
+ inviterId : userId ,
231
267
} ,
232
268
data : {
233
269
updatedAt : new Date ( ) ,
@@ -241,24 +277,24 @@ export async function resendInvite({ inviteId }: { inviteId: string }) {
241
277
242
278
export async function revokeInvite ( {
243
279
userId,
244
- slug ,
280
+ orgSlug ,
245
281
inviteId,
246
282
} : {
247
283
userId : string ;
248
- slug : string ;
284
+ orgSlug : string ;
249
285
inviteId : string ;
250
286
} ) {
251
- const org = await prisma . organization . findFirst ( {
252
- where : { slug, members : { some : { userId } } } ,
253
- } ) ;
254
-
255
- if ( ! org ) {
256
- throw new Error ( "User does not have access to this organization" ) ;
257
- }
258
287
const invite = await prisma . orgMemberInvite . delete ( {
259
288
where : {
260
289
id : inviteId ,
261
- organizationId : org . id ,
290
+ organization : {
291
+ slug : orgSlug ,
292
+ members : {
293
+ some : {
294
+ userId,
295
+ } ,
296
+ } ,
297
+ } ,
262
298
} ,
263
299
select : {
264
300
email : true ,
0 commit comments