feat: Auto accept on org verify (#10037)

Co-authored-by: Leo Giovanetti <hello@leog.me>
pull/9928/head
sean-brydon 2023-07-11 09:30:45 +01:00 committed by GitHub
parent 4f423ba692
commit 6d35750784
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 65 additions and 1 deletions

View File

@ -57,5 +57,69 @@ export const adminVerifyHandler = async ({ input }: AdminVerifyOptions) => {
}, },
}); });
return { ok: true, message: "Verified Organization" }; const foundUsersWithMatchingEmailDomain = await prisma.user.findMany({
where: {
email: {
endsWith: acceptedEmailDomain,
},
teams: {
some: {
teamId: input.orgId,
},
},
},
select: {
id: true,
email: true,
},
});
const userIds = foundUsersWithMatchingEmailDomain.map((user) => user.id);
const userEmails = foundUsersWithMatchingEmailDomain.map((user) => user.email);
await prisma.$transaction([
prisma.membership.updateMany({
where: {
userId: {
in: userIds,
},
OR: [
{
team: {
parentId: input.orgId,
},
},
{
teamId: input.orgId,
},
],
},
data: {
accepted: true,
},
}),
prisma.user.updateMany({
where: {
id: {
in: userIds,
},
},
data: {
organizationId: input.orgId,
},
}),
prisma.verificationToken.deleteMany({
where: {
identifier: {
in: userEmails,
},
teamId: input.orgId,
},
}),
]);
return {
ok: true,
message: `Verified Organization - Auto accepted all members ending in ${acceptedEmailDomain}`,
};
}; };