fix: fetching event-types of org users apiv2 (#18004)

This commit is contained in:
Morgan authored and GitHub committed 2024-12-05 06:02:19 +00:00
1 parent ab2ab31eef
commit 16a7cf6d04
7 files changed
+255 -36

No files matched your search

@@ -7,9 +7,9 @@ import { User } from "@calcom/prisma/client";
export class UsersService {
constructor(private readonly usersRepository: UsersRepository) {}
async getByUsernames(usernames: string[]) {
async getByUsernames(usernames: string[], orgSlug?: string, orgId?: number) {
const users = await Promise.all(
usernames.map((username) => this.usersRepository.findByUsername(username))
usernames.map((username) => this.usersRepository.findByUsername(username, orgSlug, orgId))
);
const usersFiltered: User[] = [];
@@ -142,11 +142,21 @@ export class UsersRepository {
});
}
async findByUsername(username: string) {
async findByUsername(username: string, orgSlug?: string, orgId?: number) {
return this.dbRead.prisma.user.findFirst({
where: {
username,
},
where:
orgId || orgSlug
? {
profiles: {
some: {
organization: orgSlug ? { slug: orgSlug } : { id: orgId },
username: username,
},
},
}
: {
username,
},
});
}