Skip to content

Commit 28b8e1c

Browse files
committed
fix: replace bookingTimeStatus with the denormalized table
1 parent 6464f34 commit 28b8e1c

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
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

+12-12
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ const buildBaseWhereCondition = async ({
4949
isAll,
5050
ctx,
5151
}: BuildBaseWhereConditionType): Promise<{
52-
whereCondition: Prisma.BookingTimeStatusWhereInput;
52+
whereCondition: Prisma.BookingTimeStatusDenormalizedWhereInput;
5353
isEmptyResponse?: boolean;
5454
}> => {
55-
let whereCondition: Prisma.BookingTimeStatusWhereInput = {};
56-
const ANDConditions: Prisma.BookingTimeStatusWhereInput[] = [];
55+
let whereCondition: Prisma.BookingTimeStatusDenormalizedWhereInput = {};
56+
const ANDConditions: Prisma.BookingTimeStatusDenormalizedWhereInput[] = [];
5757
// EventType Filter
5858
if (eventTypeId) ANDConditions.push({ OR: [{ eventTypeId }, { eventParentId: eventTypeId }] });
5959
// User/Member filter
@@ -588,7 +588,7 @@ export const insightsRouter = router({
588588
},
589589
};
590590

591-
const bookingsFromSelected = await ctx.insightsDb.bookingTimeStatus.groupBy({
591+
const bookingsFromSelected = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
592592
by: ["eventTypeId"],
593593
where: bookingWhere,
594594
_count: {
@@ -725,7 +725,7 @@ export const insightsRouter = router({
725725

726726
const startOfEndOf = timeView === "year" ? "year" : timeView === "month" ? "month" : "week";
727727

728-
const allBookings = await ctx.insightsDb.bookingTimeStatus.findMany({
728+
const allBookings = await ctx.insightsDb.bookingTimeStatusDenormalized.findMany({
729729
select: {
730730
eventLength: true,
731731
createdAt: true,
@@ -795,7 +795,7 @@ export const insightsRouter = router({
795795
status: "CANCELLED",
796796
};
797797

798-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
798+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
799799
by: ["userId"],
800800
where: bookingWhere,
801801
_count: {
@@ -877,7 +877,7 @@ export const insightsRouter = router({
877877
},
878878
};
879879

880-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
880+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
881881
by: ["userId"],
882882
where: bookingWhere,
883883
_count: {
@@ -958,7 +958,7 @@ export const insightsRouter = router({
958958
},
959959
};
960960

961-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
961+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
962962
by: ["userId"],
963963
where: bookingWhere,
964964
_count: {
@@ -1255,7 +1255,7 @@ export const insightsRouter = router({
12551255
];
12561256
}
12571257

1258-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.findMany({
1258+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.findMany({
12591259
where: bookingWhere,
12601260
orderBy: {
12611261
endTime: "desc",
@@ -1334,7 +1334,7 @@ export const insightsRouter = router({
13341334
noShowHost: true,
13351335
};
13361336

1337-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
1337+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
13381338
by: ["userId"],
13391339
where: bookingWhere,
13401340
_count: {
@@ -1413,7 +1413,7 @@ export const insightsRouter = router({
14131413
rating: { not: null },
14141414
};
14151415

1416-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
1416+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
14171417
by: ["userId"],
14181418
where: bookingWhere,
14191419
_avg: {
@@ -1492,7 +1492,7 @@ export const insightsRouter = router({
14921492
rating: { not: null },
14931493
};
14941494

1495-
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatus.groupBy({
1495+
const bookingsFromTeam = await ctx.insightsDb.bookingTimeStatusDenormalized.groupBy({
14961496
by: ["userId"],
14971497
where: bookingWhere,
14981498
_avg: {

0 commit comments

Comments
 (0)