fix: replace bookingTimeStatus with bookingTimeStatusDenormalized (#21028)

* test: Add unit tests for buildBaseWhereCondition function

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* refactor: Export buildBaseWhereCondition function instead of copying it

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* refactor: Remove implementation detail checks from tests

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* test: Fix tests to match actual function behavior

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* test: Fix test issues with buildBaseWhereCondition

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* test: Update tests to match actual function behavior

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* fix: Address security issues in buildBaseWhereCondition function

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* refactor: Simplify buildBaseWhereCondition function

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* refactor: Simplify code and remove isEmptyResponse property

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* refactor: Use array of conditions approach for buildBaseWhereCondition

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* refactor: Make buildBaseWhereCondition implementation consistent and update tests

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* fix: Fix incorrect usage of buildBaseWhereCondition function

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* chore: Revert yarn.lock changes

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* fix: Comment out non-existent Sentry API method to fix type error

Co-Authored-By: eunjae@cal.com <eunjae@cal.com>

* Revert "fix: Comment out non-existent Sentry API method to fix type error"

This reverts commit 44c21a7396a518c63047b33967cd8af7e6e4f268.

* remove unnecessary if-statement

* fix: replace bookingTimeStatus with bookingTimeStatusDenormalized

* change column

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: eunjae@cal.com <eunjae@cal.com>
This commit is contained in:
Eunjae Lee
2025-05-21 16:10:43 +00:00
committed by GitHub
co-authored by eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> eunjae@cal.com <eunjae@cal.com> Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> eunjae@cal.com <eunjae@cal.com>
parent f84c8239e7
commit 41a6035a12
3 changed files with 31 additions and 31 deletions
@@ -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: {
+15 -15
View File
@@ -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}::timestamp
AND ${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 size
const 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 = {
@@ -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 Filter
if (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: {