Scheduling infrastructure for absolutely everyone.
fix: replace bookingTimeStatus with bookingTimeStatusDenormalized (#21028)
Eunjae Lee41a6035a12bf
diff --git a/apps/web/app/api/cron/monthlyDigestEmail/route.ts b/apps/web/app/api/cron/monthlyDigestEmail/route.tsindex c6e959c1db2..4f1a42ce47b 100644--- a/apps/web/app/api/cron/monthlyDigestEmail/route.ts+++ b/apps/web/app/api/cron/monthlyDigestEmail/route.ts@@ -95,7 +95,7 @@ async function postHandler(request: NextRequest) {const userIdsFromTeams = team.members.map((u) => u.userId);// Booking Events- const whereConditional: Prisma.BookingTimeStatusWhereInput = {+ const whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput = {OR: [{teamId: team.id,@@ -122,7 +122,7 @@ async function postHandler(request: NextRequest) {EventData["Cancelled"] = countGroupedByStatus["cancelled"];// Most Booked Event Type- const bookingWhere: Prisma.BookingTimeStatusWhereInput = {+ const bookingWhere: Prisma.BookingTimeStatusDenormalizedWhereInput = {createdAt: {gte: dayjs(firstDateOfMonth).startOf("day").toDate(),lte: dayjs(new Date()).endOf("day").toDate(),@@ -141,7 +141,7 @@ async function postHandler(request: NextRequest) {],};- const bookingsFromSelected = await prisma.bookingTimeStatus.groupBy({+ const bookingsFromSelected = await prisma.bookingTimeStatusDenormalized.groupBy({by: ["eventTypeId"],where: bookingWhere,_count: {@@ -234,7 +234,7 @@ async function postHandler(request: NextRequest) {});// Most booked members- const bookingsFromTeam = await prisma.bookingTimeStatus.groupBy({+ const bookingsFromTeam = await prisma.bookingTimeStatusDenormalized.groupBy({by: ["userId"],where: bookingWhere,_count: {diff --git a/packages/features/insights/server/events.ts b/packages/features/insights/server/events.tsindex be79d350b4d..f0f75047e22 100644--- a/packages/features/insights/server/events.ts+++ b/packages/features/insights/server/events.ts@@ -63,7 +63,7 @@ function buildSqlCondition(condition: any): string {class EventsInsights {static countGroupedByStatusForRanges = async (- whereConditional: Prisma.BookingTimeStatusWhereInput,+ whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput,startDate: Dayjs,endDate: Dayjs,timeView: "week" | "month" | "year" | "day"@@ -95,9 +95,9 @@ class EventsInsights {"timeStatus","noShowHost"FROM- "BookingTimeStatus"+ "BookingTimeStatusDenormalized"JOIN- "Attendee" "a" ON "a"."bookingId" = "BookingTimeStatus"."id"+ "Attendee" "a" ON "a"."bookingId" = "BookingTimeStatusDenormalized"."id"WHERE"createdAt" BETWEEN ${formattedStartDate}::timestamp AND ${formattedEndDate}::timestampAND ${Prisma.raw(whereClause)}@@ -185,8 +185,8 @@ class EventsInsights {return aggregate;};- static getTotalNoShowGuests = async (where: Prisma.BookingTimeStatusWhereInput) => {- const bookings = await prisma.bookingTimeStatus.findMany({+ static getTotalNoShowGuests = async (where: Prisma.BookingTimeStatusDenormalizedWhereInput) => {+ const bookings = await prisma.bookingTimeStatusDenormalized.findMany({where,select: {id: true,@@ -206,8 +206,8 @@ class EventsInsights {return totalNoShowGuests;};- static countGroupedByStatus = async (where: Prisma.BookingTimeStatusWhereInput) => {- const data = await prisma.bookingTimeStatus.groupBy({+ static countGroupedByStatus = async (where: Prisma.BookingTimeStatusDenormalizedWhereInput) => {+ const data = await prisma.bookingTimeStatusDenormalized.groupBy({where,by: ["timeStatus", "noShowHost"],_count: {@@ -237,8 +237,8 @@ class EventsInsights {);};- static getAverageRating = async (whereConditional: Prisma.BookingTimeStatusWhereInput) => {- return await prisma.bookingTimeStatus.aggregate({+ static getAverageRating = async (whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput) => {+ return await prisma.bookingTimeStatusDenormalized.aggregate({_avg: {rating: true,},@@ -251,8 +251,8 @@ class EventsInsights {});};- static getTotalCSAT = async (whereConditional: Prisma.BookingTimeStatusWhereInput) => {- const result = await prisma.bookingTimeStatus.findMany({+ static getTotalCSAT = async (whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput) => {+ const result = await prisma.bookingTimeStatusDenormalized.findMany({where: {...whereConditional,rating: {@@ -385,11 +385,11 @@ class EventsInsights {const limit = props.limit ?? 100; // Default batch sizeconst offset = props.offset ?? 0;- const totalCountPromise = prisma.bookingTimeStatus.count({+ const totalCountPromise = prisma.bookingTimeStatusDenormalized.count({where: whereConditional,});- const csvDataPromise = prisma.bookingTimeStatus.findMany({+ const csvDataPromise = prisma.bookingTimeStatusDenormalized.findMany({select: {id: true,uid: true,@@ -402,7 +402,7 @@ class EventsInsights {endTime: true,paid: true,userEmail: true,- username: true,+ userUsername: true,rating: true,ratingFeedback: true,noShowHost: true,@@ -496,7 +496,7 @@ class EventsInsights {} = props;// Obtain the where conditional- let whereConditional: Prisma.BookingTimeStatusWhereInput = {};+ let whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput = {};if (startDate && endDate) {whereConditional.createdAt = {diff --git a/packages/features/insights/server/trpc-router.ts b/packages/features/insights/server/trpc-router.tsindex 65ede552fa5..9421887e9ca 100644--- a/packages/features/insights/server/trpc-router.ts+++ b/packages/features/insights/server/trpc-router.ts@@ -49,9 +49,9 @@ export const buildBaseWhereCondition = async ({isAll,ctx,}: BuildBaseWhereConditionType): Promise<{- whereCondition: Prisma.BookingTimeStatusWhereInput;+ whereCondition: Prisma.BookingTimeStatusDenormalizedWhereInput;}> => {- const conditions: Prisma.BookingTimeStatusWhereInput[] = [];+ const conditions: Prisma.BookingTimeStatusDenormalizedWhereInput[] = [];// EventType Filterif (eventTypeId) {@@ -152,7 +152,7 @@ export const buildBaseWhereCondition = async ({});}- let whereCondition: Prisma.BookingTimeStatusWhereInput = {};+ let whereCondition: Prisma.BookingTimeStatusDenormalizedWhereInput = {};if (conditions.length === 1) {whereCondition = conditions[0];@@ -597,7 +597,7 @@ export const insightsRouter = router({},};- const bookingsFromSelected = await ctx.insightsDb.bookingTimeStatus.groupBy({+ const bookingsFromSelected = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({by: ["eventTypeId"],where: bookingWhere,_count: {@@ -734,7 +734,7 @@ export const insightsRouter = router({const startOfEndOf = timeView === "year" ? "year" : timeView === "month" ? "month" : "week";- const allBookings = await ctx.insightsDb.bookingTimeStatus.findMany({+ const allBookings = await ctx.insightsDb.bookingTimeStatusDenormalized.findMany({select: {eventLength: true,createdAt: true,@@ -804,7 +804,7 @@ export const insightsRouter = router({status: "CANCELLED",};- const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({+ const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({by: ["userId"],where: bookingWhere,_count: {@@ -886,7 +886,7 @@ export const insightsRouter = router({},};- const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({+ const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({by: ["userId"],where: bookingWhere,_count: {@@ -967,7 +967,7 @@ export const insightsRouter = router({},};- const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({+ const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({by: ["userId"],where: bookingWhere,_count: {@@ -1262,7 +1262,7 @@ export const insightsRouter = router({];}- const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.findMany({+ const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.findMany({where: bookingWhere,orderBy: {endTime: "desc",@@ -1339,7 +1339,7 @@ export const insightsRouter = router({noShowHost: true,};- const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({+ const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({by: ["userId"],where: bookingWhere,_count: {@@ -1417,7 +1417,7 @@ export const insightsRouter = router({rating: { not: null },};- const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({+ const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({by: ["userId"],where: bookingWhere,_avg: {@@ -1495,7 +1495,7 @@ export const insightsRouter = router({rating: { not: null },};- const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({+ const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({by: ["userId"],where: bookingWhere,_avg: {