@@ -120,10 +120,17 @@ export async function inviteMembers({
120120 } ) ;
121121}
122122
123- export async function getInviteFromToken ( { token } : { token : string } ) {
123+ export async function getInviteFromToken ( { token, userId } : { token : string ; userId : string } ) {
124124 return await prisma . orgMemberInvite . findFirst ( {
125125 where : {
126126 token,
127+ organization : {
128+ members : {
129+ some : {
130+ userId,
131+ } ,
132+ } ,
133+ } ,
127134 } ,
128135 include : {
129136 organization : true ,
@@ -153,6 +160,13 @@ export async function acceptInvite({ userId, inviteId }: { userId: string; invit
153160 const invite = await tx . orgMemberInvite . delete ( {
154161 where : {
155162 id : inviteId ,
163+ organization : {
164+ members : {
165+ some : {
166+ userId,
167+ } ,
168+ } ,
169+ } ,
156170 } ,
157171 include : {
158172 organization : {
@@ -188,6 +202,13 @@ export async function acceptInvite({ userId, inviteId }: { userId: string; invit
188202 const remainingInvites = await tx . orgMemberInvite . findMany ( {
189203 where : {
190204 email : invite . email ,
205+ organization : {
206+ members : {
207+ some : {
208+ userId,
209+ } ,
210+ } ,
211+ } ,
191212 } ,
192213 } ) ;
193214
@@ -201,6 +222,13 @@ export async function declineInvite({ userId, inviteId }: { userId: string; invi
201222 const declinedInvite = await prisma . orgMemberInvite . delete ( {
202223 where : {
203224 id : inviteId ,
225+ organization : {
226+ members : {
227+ some : {
228+ userId,
229+ } ,
230+ } ,
231+ } ,
204232 } ,
205233 include : {
206234 organization : true ,
@@ -217,17 +245,25 @@ export async function declineInvite({ userId, inviteId }: { userId: string; invi
217245 const remainingInvites = await prisma . orgMemberInvite . findMany ( {
218246 where : {
219247 email : user ! . email ,
248+ organization : {
249+ members : {
250+ some : {
251+ userId,
252+ } ,
253+ } ,
254+ } ,
220255 } ,
221256 } ) ;
222257
223258 return { remainingInvites, organization : declinedInvite . organization } ;
224259 } ) ;
225260}
226261
227- export async function resendInvite ( { inviteId } : { inviteId : string } ) {
262+ export async function resendInvite ( { inviteId, userId } : { inviteId : string ; userId : string } ) {
228263 return await prisma . orgMemberInvite . update ( {
229264 where : {
230265 id : inviteId ,
266+ inviterId : userId ,
231267 } ,
232268 data : {
233269 updatedAt : new Date ( ) ,
@@ -241,24 +277,24 @@ export async function resendInvite({ inviteId }: { inviteId: string }) {
241277
242278export async function revokeInvite ( {
243279 userId,
244- slug ,
280+ orgSlug ,
245281 inviteId,
246282} : {
247283 userId : string ;
248- slug : string ;
284+ orgSlug : string ;
249285 inviteId : string ;
250286} ) {
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- }
258287 const invite = await prisma . orgMemberInvite . delete ( {
259288 where : {
260289 id : inviteId ,
261- organizationId : org . id ,
290+ organization : {
291+ slug : orgSlug ,
292+ members : {
293+ some : {
294+ userId,
295+ } ,
296+ } ,
297+ } ,
262298 } ,
263299 select : {
264300 email : true ,
0 commit comments