Skip to content

Commit d3c79db

Browse files
committed
delete pending invites once a member request is accepted
1 parent e7b28f1 commit d3c79db

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

packages/web/src/actions.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,30 +1580,50 @@ export const approveAccountRequest = async (requestId: string, domain: string) =
15801580
} satisfies ServiceError;
15811581
}
15821582

1583-
await prisma.$transaction([
1584-
prisma.user.update({
1583+
const res = await prisma.$transaction(async (tx) => {
1584+
await tx.user.update({
15851585
where: {
15861586
id: request.requestedById,
15871587
},
15881588
data: {
15891589
pendingApproval: false,
15901590
},
1591-
}),
1591+
});
15921592

1593-
prisma.userToOrg.create({
1593+
await tx.userToOrg.create({
15941594
data: {
15951595
userId: request.requestedById,
15961596
orgId: org.id,
15971597
role: "MEMBER",
15981598
},
1599-
}),
1599+
});
16001600

1601-
prisma.accountRequest.delete({
1601+
await tx.accountRequest.delete({
16021602
where: {
16031603
id: requestId,
16041604
},
1605-
}),
1606-
]);
1605+
});
1606+
1607+
const invites = await tx.invite.findMany({
1608+
where: {
1609+
recipientEmail: request.requestedBy.email!,
1610+
orgId: org.id,
1611+
},
1612+
})
1613+
1614+
for (const invite of invites) {
1615+
console.log(`Account request approved. Deleting invite ${invite.id} for ${request.requestedBy.email}`);
1616+
await tx.invite.delete({
1617+
where: {
1618+
id: invite.id,
1619+
},
1620+
});
1621+
}
1622+
});
1623+
1624+
if (isServiceError(res)) {
1625+
return res;
1626+
}
16071627

16081628
// Send approval email to the user
16091629
if (env.SMTP_CONNECTION_URL && env.EMAIL_FROM_ADDRESS) {

0 commit comments

Comments
 (0)