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

This commit is contained in:
Morgan
2024-12-05 06:02:19 +00:00
committed by GitHub
parent ab2ab31eef
commit 16a7cf6d04
7 changed files with 255 additions and 36 deletions
@@ -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,
},
});
}