chore: Remove passing optional prisma select prop to Repository classes (#16600)
This commit is contained in:
@@ -43,12 +43,8 @@ const Page = async ({ params }: PageProps) => {
|
||||
let userData, schedule, travelSchedules;
|
||||
|
||||
try {
|
||||
userData = await UserRepository.findById({
|
||||
id: userId,
|
||||
select: {
|
||||
timeZone: true,
|
||||
defaultScheduleId: true,
|
||||
},
|
||||
userData = await UserRepository.getTimeZoneAndDefaultScheduleId({
|
||||
userId,
|
||||
});
|
||||
if (!userData?.timeZone || !userData?.defaultScheduleId) {
|
||||
throw new Error("timeZone and defaultScheduleId not found");
|
||||
|
||||
@@ -12,7 +12,7 @@ import MeetingNotStarted from "~/videos/views/videos-meeting-not-started-single-
|
||||
|
||||
export const generateMetadata = async ({ params, searchParams }: _PageProps) => {
|
||||
const p = { ...params, ...searchParams };
|
||||
const booking = await BookingRepository.findBookingByUidWithOptionalSelect({
|
||||
const booking = await BookingRepository.findBookingByUid({
|
||||
bookingUid: typeof p?.uid === "string" ? p.uid : "",
|
||||
});
|
||||
|
||||
|
||||
@@ -20,34 +20,8 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
|
||||
const ssr = await ssrInit(context);
|
||||
|
||||
const booking = await BookingRepository.findBookingByUidWithOptionalSelect({
|
||||
const booking = await BookingRepository.findBookingForMeetingPage({
|
||||
bookingUid: context.query.uid as string,
|
||||
select: {
|
||||
uid: true,
|
||||
description: true,
|
||||
isRecorded: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
timeZone: true,
|
||||
name: true,
|
||||
email: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
references: {
|
||||
select: {
|
||||
id: true,
|
||||
uid: true,
|
||||
type: true,
|
||||
meetingUrl: true,
|
||||
meetingPassword: true,
|
||||
},
|
||||
where: {
|
||||
type: "daily_video",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!booking || booking.references.length === 0 || !booking.references[0].meetingUrl) {
|
||||
|
||||
@@ -6,23 +6,8 @@ import { type inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
|
||||
export type PageProps = inferSSRProps<typeof getServerSideProps>;
|
||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
const booking = await BookingRepository.findBookingByUidWithOptionalSelect({
|
||||
const booking = await BookingRepository.findBookingForMeetingEndedPage({
|
||||
bookingUid: context.query.uid as string,
|
||||
select: {
|
||||
uid: true,
|
||||
user: {
|
||||
select: {
|
||||
credentials: true,
|
||||
},
|
||||
},
|
||||
references: {
|
||||
select: {
|
||||
uid: true,
|
||||
type: true,
|
||||
meetingUrl: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!booking) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
|
||||
// change the type
|
||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
const booking = await BookingRepository.findBookingByUidWithOptionalSelect({
|
||||
const booking = await BookingRepository.findBookingByUid({
|
||||
bookingUid: context.query.uid as string,
|
||||
});
|
||||
|
||||
|
||||
@@ -113,18 +113,71 @@ export class BookingRepository {
|
||||
return allBookings;
|
||||
}
|
||||
|
||||
static async findBookingByUidWithOptionalSelect({
|
||||
bookingUid,
|
||||
select,
|
||||
}: {
|
||||
bookingUid: string;
|
||||
select?: Prisma.BookingSelect;
|
||||
}) {
|
||||
static async findBookingByUid({ bookingUid }: { bookingUid: string }) {
|
||||
return await prisma.booking.findUnique({
|
||||
where: {
|
||||
uid: bookingUid,
|
||||
},
|
||||
select: { ...bookingMinimalSelect, ...select },
|
||||
select: bookingMinimalSelect,
|
||||
});
|
||||
}
|
||||
|
||||
static async findBookingForMeetingPage({ bookingUid }: { bookingUid: string }) {
|
||||
return await prisma.booking.findUnique({
|
||||
where: {
|
||||
uid: bookingUid,
|
||||
},
|
||||
select: {
|
||||
...bookingMinimalSelect,
|
||||
uid: true,
|
||||
description: true,
|
||||
isRecorded: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
timeZone: true,
|
||||
name: true,
|
||||
email: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
references: {
|
||||
select: {
|
||||
id: true,
|
||||
uid: true,
|
||||
type: true,
|
||||
meetingUrl: true,
|
||||
meetingPassword: true,
|
||||
},
|
||||
where: {
|
||||
type: "daily_video",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
static async findBookingForMeetingEndedPage({ bookingUid }: { bookingUid: string }) {
|
||||
return await prisma.booking.findUnique({
|
||||
where: {
|
||||
uid: bookingUid,
|
||||
},
|
||||
select: {
|
||||
...bookingMinimalSelect,
|
||||
uid: true,
|
||||
user: {
|
||||
select: {
|
||||
credentials: true,
|
||||
},
|
||||
},
|
||||
references: {
|
||||
select: {
|
||||
uid: true,
|
||||
type: true,
|
||||
meetingUrl: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -239,12 +239,12 @@ export class UserRepository {
|
||||
};
|
||||
}
|
||||
|
||||
static async findById({ id, select }: { id: number; select?: Prisma.UserSelect }) {
|
||||
static async findById({ id }: { id: number }) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select: { ...userSelect, ...select },
|
||||
select: userSelect,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
@@ -566,6 +566,18 @@ export class UserRepository {
|
||||
return teamIds;
|
||||
}
|
||||
|
||||
static async getTimeZoneAndDefaultScheduleId({ userId }: { userId: number }) {
|
||||
return await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
select: {
|
||||
timeZone: true,
|
||||
defaultScheduleId: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
static async adminFindById(userId: number) {
|
||||
return await prisma.user.findUniqueOrThrow({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user