fix: including parentId when filter by eventTypeId happens (#10262)

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
alannncandPeer Richelsen authored and GitHub committed 2023-07-20 12:19:13 -07:00
1 parent 939a32813f
commit cd88b688f4
4 files changed
+90 -20

No files matched your search

@@ -86,6 +86,17 @@ class EventsInsights {
return baseBookings;
};
static getTotalCompletedEvents = async (bookingIds: number[]) => {
return await prisma.bookingTimeStatus.count({
where: {
id: {
in: bookingIds,
},
timeStatus: "completed",
},
});
};
static getTotalRescheduledEvents = async (bookingIds: number[]) => {
return await prisma.bookingTimeStatus.count({
where: {
@@ -133,7 +133,14 @@ export const insightsRouter = router({
let teamConditional: Prisma.TeamWhereInput = {};
if (eventTypeId) {
whereConditional["eventTypeId"] = eventTypeId;
whereConditional["OR"] = [
{
eventTypeId,
},
{
eventParentId: eventTypeId,
},
];
}
if (memberUserId) {
whereConditional["userId"] = memberUserId;
@@ -226,6 +233,7 @@ export const insightsRouter = router({
const startTimeEndTimeDiff = dayjs(endDate).diff(dayjs(startDate), "day");
const baseBookingIds = baseBookings.map((b) => b.id);
const totalCompleted = await EventsInsights.getTotalCompletedEvents(baseBookingIds);
const totalRescheduled = await EventsInsights.getTotalRescheduledEvents(baseBookingIds);
@@ -257,7 +265,7 @@ export const insightsRouter = router({
deltaPrevious: EventsInsights.getPercentage(baseBookings.length, lastPeriodBaseBookings.length),
},
completed: {
count: baseBookings.length - totalCancelled - totalRescheduled,
count: totalCompleted,
deltaPrevious: EventsInsights.getPercentage(
baseBookings.length - totalCancelled - totalRescheduled,
lastPeriodBaseBookings.length - lastPeriodTotalCancelled - lastPeriodTotalRescheduled
@@ -284,6 +292,7 @@ export const insightsRouter = router({
) {
return emptyResponseEventsByStatus;
}
return result;
}),
eventsTimeline: userBelongsToTeamProcedure
@@ -410,7 +419,14 @@ export const insightsRouter = router({
if (eventTypeId && !!whereConditional) {
whereConditional = {
eventTypeId: eventTypeId,
OR: [
{
eventTypeId,
},
{
eventParentId: eventTypeId,
},
],
};
}
@@ -864,7 +880,14 @@ export const insightsRouter = router({
};
if (eventTypeId) {
bookingWhere.eventTypeId = eventTypeId;
bookingWhere["OR"] = [
{
eventTypeId,
},
{
eventParentId: eventTypeId,
},
];
}
if (isAll && user.isOwnerAdminOfParentTeam && user.organizationId) {
@@ -0,0 +1,35 @@
-- View: public.BookingsTimeStatus
-- DROP VIEW public."BookingsTimeStatus";
CREATE OR REPLACE VIEW public."BookingTimeStatus"
AS
SELECT "Booking".id,
"Booking".uid,
"Booking"."eventTypeId",
"Booking".title,
"Booking".description,
"Booking"."startTime",
"Booking"."endTime",
"Booking"."createdAt",
"Booking".location,
"Booking".paid,
"Booking".status,
"Booking".rescheduled,
"Booking"."userId",
"et"."teamId",
"et"."length" as "eventLength",
CASE
WHEN "Booking".rescheduled IS TRUE THEN 'rescheduled'::text
WHEN "Booking".status = 'cancelled'::"BookingStatus" AND "Booking".rescheduled IS FALSE THEN 'cancelled'::text
WHEN "Booking"."endTime" < now() THEN 'completed'::text
WHEN "Booking"."endTime" > now() THEN 'uncompleted'::text
ELSE NULL::text
END AS "timeStatus",
"et"."parentId" as "eventParentId"
FROM "Booking"
LEFT JOIN "EventType" et ON "Booking"."eventTypeId" = et.id
LEFT JOIN "Membership" mb ON "mb"."userId" = "Booking"."userId";
+17 -16
View File
@@ -877,20 +877,21 @@ model SelectedSlots {
}
view BookingTimeStatus {
id Int @unique
uid String?
eventTypeId Int?
title String?
description String?
startTime DateTime?
endTime DateTime?
createdAt DateTime?
location String?
paid Boolean?
status BookingStatus?
rescheduled Boolean?
userId Int?
teamId Int?
eventLength Int?
timeStatus String?
id Int @unique
uid String?
eventTypeId Int?
title String?
description String?
startTime DateTime?
endTime DateTime?
createdAt DateTime?
location String?
paid Boolean?
status BookingStatus?
rescheduled Boolean?
userId Int?
teamId Int?
eventLength Int?
timeStatus String?
eventParentId Int?
}