@@ -473,6 +473,7 @@ export const createApiKey = async (name: string, domain: string): Promise<{ key:
473473 id : org . id . toString ( ) ,
474474 type : "org"
475475 } ,
476+ orgId : org . id ,
476477 metadata : {
477478 message : `API key ${ name } already exists` ,
478479 api_key : name
@@ -505,6 +506,7 @@ export const createApiKey = async (name: string, domain: string): Promise<{ key:
505506 id : apiKey . hash ,
506507 type : "api_key"
507508 } ,
509+ orgId : org . id ,
508510 metadata : {
509511 api_key : name
510512 }
@@ -517,7 +519,7 @@ export const createApiKey = async (name: string, domain: string): Promise<{ key:
517519
518520export const deleteApiKey = async ( name : string , domain : string ) : Promise < { success : boolean } | ServiceError > => sew ( ( ) =>
519521 withAuth ( ( userId ) =>
520- withOrgMembership ( userId , domain , async ( ) => {
522+ withOrgMembership ( userId , domain , async ( { org } ) => {
521523 const apiKey = await prisma . apiKey . findFirst ( {
522524 where : {
523525 name,
@@ -536,6 +538,7 @@ export const deleteApiKey = async (name: string, domain: string): Promise<{ succ
536538 id : domain ,
537539 type : "org"
538540 } ,
541+ orgId : org . id ,
539542 metadata : {
540543 message : `API key ${ name } not found for user ${ userId } ` ,
541544 api_key : name
@@ -564,6 +567,7 @@ export const deleteApiKey = async (name: string, domain: string): Promise<{ succ
564567 id : apiKey . hash ,
565568 type : "api_key"
566569 } ,
570+ orgId : org . id ,
567571 metadata : {
568572 api_key : name
569573 }
@@ -978,6 +982,7 @@ export const createInvites = async (emails: string[], domain: string): Promise<{
978982 id : org . id . toString ( ) ,
979983 type : "org"
980984 } ,
985+ orgId : org . id ,
981986 metadata : {
982987 message : error ,
983988 emails : emails . join ( ", " )
@@ -1001,6 +1006,7 @@ export const createInvites = async (emails: string[], domain: string): Promise<{
10011006 id : org . id . toString ( ) ,
10021007 type : "org"
10031008 } ,
1009+ orgId : org . id ,
10041010 metadata : {
10051011 message : "Organization has reached maximum number of seats" ,
10061012 emails : emails . join ( ", " )
@@ -1130,6 +1136,7 @@ export const createInvites = async (emails: string[], domain: string): Promise<{
11301136 id : org . id . toString ( ) ,
11311137 type : "org"
11321138 } ,
1139+ orgId : org . id ,
11331140 metadata : {
11341141 emails : emails . join ( ", " )
11351142 }
@@ -1206,6 +1213,19 @@ export const redeemInvite = async (inviteId: string): Promise<{ success: boolean
12061213 return user ;
12071214 }
12081215
1216+ const invite = await prisma . invite . findUnique ( {
1217+ where : {
1218+ id : inviteId ,
1219+ } ,
1220+ include : {
1221+ org : true ,
1222+ }
1223+ } ) ;
1224+
1225+ if ( ! invite ) {
1226+ return notFound ( ) ;
1227+ }
1228+
12091229 const failAuditCallback = async ( error : string ) => {
12101230 await auditService . createAudit ( {
12111231 action : "user.invite_accept_failed" ,
@@ -1217,23 +1237,13 @@ export const redeemInvite = async (inviteId: string): Promise<{ success: boolean
12171237 id : inviteId ,
12181238 type : "invite"
12191239 } ,
1240+ orgId : invite . org . id ,
12201241 metadata : {
12211242 message : error
12221243 }
12231244 } ) ;
12241245 }
1225- const invite = await prisma . invite . findUnique ( {
1226- where : {
1227- id : inviteId ,
1228- } ,
1229- include : {
1230- org : true ,
1231- }
1232- } ) ;
12331246
1234- if ( ! invite ) {
1235- return notFound ( ) ;
1236- }
12371247
12381248 const hasAvailability = await orgHasAvailability ( invite . org . domain ) ;
12391249 if ( ! hasAvailability ) {
@@ -1293,6 +1303,7 @@ export const redeemInvite = async (inviteId: string): Promise<{ success: boolean
12931303 id : user . id ,
12941304 type : "user"
12951305 } ,
1306+ orgId : invite . org . id ,
12961307 target : {
12971308 id : accountRequest . id ,
12981309 type : "account_join_request"
@@ -1325,6 +1336,7 @@ export const redeemInvite = async (inviteId: string): Promise<{ success: boolean
13251336 id : user . id ,
13261337 type : "user"
13271338 } ,
1339+ orgId : invite . org . id ,
13281340 target : {
13291341 id : inviteId ,
13301342 type : "invite"
@@ -1394,6 +1406,7 @@ export const transferOwnership = async (newOwnerId: string, domain: string): Pro
13941406 id : org . id . toString ( ) ,
13951407 type : "org"
13961408 } ,
1409+ orgId : org . id ,
13971410 metadata : {
13981411 message : error
13991412 }
@@ -1461,6 +1474,7 @@ export const transferOwnership = async (newOwnerId: string, domain: string): Pro
14611474 id : org . id . toString ( ) ,
14621475 type : "org"
14631476 } ,
1477+ orgId : org . id ,
14641478 metadata : {
14651479 message : `Ownership transferred from ${ currentUserId } to ${ newOwnerId } `
14661480 }
@@ -1780,6 +1794,7 @@ export const approveAccountRequest = async (requestId: string, domain: string) =
17801794 id : requestId ,
17811795 type : "account_join_request"
17821796 } ,
1797+ orgId : org . id ,
17831798 metadata : {
17841799 message : error ,
17851800 }
@@ -1894,6 +1909,7 @@ export const approveAccountRequest = async (requestId: string, domain: string) =
18941909 id : userId ,
18951910 type : "user"
18961911 } ,
1912+ orgId : org . id ,
18971913 target : {
18981914 id : requestId ,
18991915 type : "account_join_request"
@@ -1930,6 +1946,7 @@ export const rejectAccountRequest = async (requestId: string, domain: string) =>
19301946 id : userId ,
19311947 type : "user"
19321948 } ,
1949+ orgId : org . id ,
19331950 target : {
19341951 id : requestId ,
19351952 type : "account_join_request"
0 commit comments