fix: Fixes username invite issue (#10998)

* Fixes username invite issue

* Ensure we only suggest email invites in org members

---------

Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
sean-brydonandUdit Takkar authored and GitHub committed 2023-09-01 17:31:45 +05:30
1 parent 0e181f6d9f
commit 376b38d4ed
4 files changed
+11 -5

No files matched your search

@@ -56,7 +56,7 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
});
const invitee = await getUserToInviteOrThrowIfExists({
usernameOrEmail,
orgId: input.teamId,
teamId: input.teamId,
isOrg: input.isOrg,
});
@@ -66,17 +66,21 @@ export async function getEmailsToInvite(usernameOrEmail: string | string[]) {
export async function getUserToInviteOrThrowIfExists({
usernameOrEmail,
orgId,
teamId,
isOrg,
}: {
usernameOrEmail: string;
orgId: number;
teamId: number;
isOrg?: boolean;
}) {
// Check if user exists in ORG or exists all together
const orgWhere = isOrg && {
organizationId: teamId,
};
const invitee = await prisma.user.findFirst({
where: {
OR: [{ username: usernameOrEmail, organizationId: orgId }, { email: usernameOrEmail }],
OR: [{ username: usernameOrEmail, ...orgWhere }, { email: usernameOrEmail }],
},
});