* Remove unused return statement * Fix return from fn instead of continuing the loop * Ensure userId is set for existing records on update * ensure that serviceAccountKey is only retrieved whenb assked
30 lines
909 B
TypeScript
30 lines
909 B
TypeScript
import type { Prisma } from "@prisma/client";
|
|
|
|
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
|
|
import { availabilityUserSelect } from "@calcom/prisma";
|
|
import { prisma } from "@calcom/prisma";
|
|
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
|
|
|
import { withSelectedCalendars } from "./withSelectedCalendars";
|
|
|
|
export async function findUsersForAvailabilityCheck({ where }: { where: Prisma.UserWhereInput }) {
|
|
const user = await prisma.user.findFirst({
|
|
where,
|
|
select: {
|
|
...availabilityUserSelect,
|
|
selectedCalendars: true,
|
|
credentials: {
|
|
select: credentialForCalendarServiceSelect,
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!user) {
|
|
return null;
|
|
}
|
|
|
|
return await enrichUserWithDelegationCredentialsIncludeServiceAccountKey({
|
|
user: withSelectedCalendars(user),
|
|
});
|
|
}
|