Skip to content

Commit 78911c7

Browse files
committed
fix: replace bookingTimeStatus with the denormalized table
1 parent b212482 commit 78911c7

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

apps/web/app/api/cron/monthlyDigestEmail/route.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function postHandler(request: NextRequest) {
9595
const userIdsFromTeams = team.members.map((u) => u.userId);
9696

9797
// Booking Events
98-
const whereConditional: Prisma.BookingTimeStatusWhereInput = {
98+
const whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput = {
9999
OR: [
100100
{
101101
teamId: team.id,
@@ -122,7 +122,7 @@ async function postHandler(request: NextRequest) {
122122
EventData["Cancelled"] = countGroupedByStatus["cancelled"];
123123

124124
// Most Booked Event Type
125-
const bookingWhere: Prisma.BookingTimeStatusWhereInput = {
125+
const bookingWhere: Prisma.BookingTimeStatusDenormalizedWhereInput = {
126126
createdAt: {
127127
gte: dayjs(firstDateOfMonth).startOf("day").toDate(),
128128
lte: dayjs(new Date()).endOf("day").toDate(),
@@ -141,7 +141,7 @@ async function postHandler(request: NextRequest) {
141141
],
142142
};
143143

144-
const bookingsFromSelected = await prisma.bookingTimeStatus.groupBy({
144+
const bookingsFromSelected = await prisma.bookingTimeStatusDenormalized.groupBy({
145145
by: ["eventTypeId"],
146146
where: bookingWhere,
147147
_count: {
@@ -234,7 +234,7 @@ async function postHandler(request: NextRequest) {
234234
});
235235

236236
// Most booked members
237-
const bookingsFromTeam = await prisma.bookingTimeStatus.groupBy({
237+
const bookingsFromTeam = await prisma.bookingTimeStatusDenormalized.groupBy({
238238
by: ["userId"],
239239
where: bookingWhere,
240240
_count: {

packages/features/insights/server/events.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function buildSqlCondition(condition: any): string {
6363

6464
class EventsInsights {
6565
static countGroupedByStatusForRanges = async (
66-
whereConditional: Prisma.BookingTimeStatusWhereInput,
66+
whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput,
6767
startDate: Dayjs,
6868
endDate: Dayjs,
6969
timeView: "week" | "month" | "year" | "day"
@@ -95,9 +95,9 @@ class EventsInsights {
9595
"timeStatus",
9696
"noShowHost"
9797
FROM
98-
"BookingTimeStatus"
98+
"BookingTimeStatusDenormalized"
9999
JOIN
100-
"Attendee" "a" ON "a"."bookingId" = "BookingTimeStatus"."id"
100+
"Attendee" "a" ON "a"."bookingId" = "BookingTimeStatusDenormalized"."id"
101101
WHERE
102102
"createdAt" BETWEEN ${formattedStartDate}::timestamp AND ${formattedEndDate}::timestamp
103103
AND ${Prisma.raw(whereClause)}
@@ -185,8 +185,8 @@ class EventsInsights {
185185
return aggregate;
186186
};
187187

188-
static getTotalNoShowGuests = async (where: Prisma.BookingTimeStatusWhereInput) => {
189-
const bookings = await prisma.bookingTimeStatus.findMany({
188+
static getTotalNoShowGuests = async (where: Prisma.BookingTimeStatusDenormalizedWhereInput) => {
189+
const bookings = await prisma.bookingTimeStatusDenormalized.findMany({
190190
where,
191191
select: {
192192
id: true,
@@ -206,8 +206,8 @@ class EventsInsights {
206206
return totalNoShowGuests;
207207
};
208208

209-
static countGroupedByStatus = async (where: Prisma.BookingTimeStatusWhereInput) => {
210-
const data = await prisma.bookingTimeStatus.groupBy({
209+
static countGroupedByStatus = async (where: Prisma.BookingTimeStatusDenormalizedWhereInput) => {
210+
const data = await prisma.bookingTimeStatusDenormalized.groupBy({
211211
where,
212212
by: ["timeStatus", "noShowHost"],
213213
_count: {
@@ -237,8 +237,8 @@ class EventsInsights {
237237
);
238238
};
239239

240-
static getAverageRating = async (whereConditional: Prisma.BookingTimeStatusWhereInput) => {
241-
return await prisma.bookingTimeStatus.aggregate({
240+
static getAverageRating = async (whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput) => {
241+
return await prisma.bookingTimeStatusDenormalized.aggregate({
242242
_avg: {
243243
rating: true,
244244
},
@@ -251,8 +251,8 @@ class EventsInsights {
251251
});
252252
};
253253

254-
static getTotalCSAT = async (whereConditional: Prisma.BookingTimeStatusWhereInput) => {
255-
const result = await prisma.bookingTimeStatus.findMany({
254+
static getTotalCSAT = async (whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput) => {
255+
const result = await prisma.bookingTimeStatusDenormalized.findMany({
256256
where: {
257257
...whereConditional,
258258
rating: {
@@ -385,11 +385,11 @@ class EventsInsights {
385385
const limit = props.limit ?? 100; // Default batch size
386386
const offset = props.offset ?? 0;
387387

388-
const totalCountPromise = prisma.bookingTimeStatus.count({
388+
const totalCountPromise = prisma.bookingTimeStatusDenormalized.count({
389389
where: whereConditional,
390390
});
391391

392-
const csvDataPromise = prisma.bookingTimeStatus.findMany({
392+
const csvDataPromise = prisma.bookingTimeStatusDenormalized.findMany({
393393
select: {
394394
id: true,
395395
uid: true,
@@ -496,7 +496,7 @@ class EventsInsights {
496496
} = props;
497497

498498
// Obtain the where conditional
499-
let whereConditional: Prisma.BookingTimeStatusWhereInput = {};
499+
let whereConditional: Prisma.BookingTimeStatusDenormalizedWhereInput = {};
500500

501501
if (startDate && endDate) {
502502
whereConditional.createdAt = {

packages/features/insights/server/trpc-router.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const buildBaseWhereCondition = async ({
4949
isAll,
5050
ctx,
5151
}: BuildBaseWhereConditionType): Promise<{
52-
whereCondition: Prisma.BookingTimeStatusWhereInput;
52+
whereCondition: Prisma.BookingTimeStatusDenormalizedWhereInput;
5353
isEmptyResponse?: boolean;
5454
}> => {
5555
let whereCondition: Prisma.BookingTimeStatusWhereInput = {};
@@ -581,7 +581,7 @@ export const insightsRouter = router({
581581
},
582582
};
583583

584-
const bookingsFromSelected = await ctx.insightsDb.bookingTimeStatus.groupBy({
584+
const bookingsFromSelected = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
585585
by: ["eventTypeId"],
586586
where: bookingWhere,
587587
_count: {
@@ -718,7 +718,7 @@ export const insightsRouter = router({
718718

719719
const startOfEndOf = timeView === "year" ? "year" : timeView === "month" ? "month" : "week";
720720

721-
const allBookings = await ctx.insightsDb.bookingTimeStatus.findMany({
721+
const allBookings = await ctx.insightsDb.bookingTimeStatusDenormalized.findMany({
722722
select: {
723723
eventLength: true,
724724
createdAt: true,
@@ -788,7 +788,7 @@ export const insightsRouter = router({
788788
status: "CANCELLED",
789789
};
790790

791-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
791+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
792792
by: ["userId"],
793793
where: bookingWhere,
794794
_count: {
@@ -870,7 +870,7 @@ export const insightsRouter = router({
870870
},
871871
};
872872

873-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
873+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
874874
by: ["userId"],
875875
where: bookingWhere,
876876
_count: {
@@ -951,7 +951,7 @@ export const insightsRouter = router({
951951
},
952952
};
953953

954-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
954+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
955955
by: ["userId"],
956956
where: bookingWhere,
957957
_count: {
@@ -1248,7 +1248,7 @@ export const insightsRouter = router({
12481248
];
12491249
}
12501250

1251-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.findMany({
1251+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.findMany({
12521252
where: bookingWhere,
12531253
orderBy: {
12541254
endTime: "desc",
@@ -1327,7 +1327,7 @@ export const insightsRouter = router({
13271327
noShowHost: true,
13281328
};
13291329

1330-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
1330+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
13311331
by: ["userId"],
13321332
where: bookingWhere,
13331333
_count: {
@@ -1406,7 +1406,7 @@ export const insightsRouter = router({
14061406
rating: { not: null },
14071407
};
14081408

1409-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
1409+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
14101410
by: ["userId"],
14111411
where: bookingWhere,
14121412
_avg: {
@@ -1485,7 +1485,7 @@ export const insightsRouter = router({
14851485
rating: { not: null },
14861486
};
14871487

1488-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
1488+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
14891489
by: ["userId"],
14901490
where: bookingWhere,
14911491
_avg: {

0 commit comments

Comments
 (0)