Fixing unconfirmed/recurring bookings (#4881)
This commit is contained in:
1 parent
0b29c5063a
commit
4e49d32c61
6 files changed
+85
-88
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { AppCategories, BookingStatus, IdentityProvider, MembershipRole, Prisma } from "@prisma/client";
|
||||
import _ from "lodash";
|
||||
import { authenticator } from "otplib";
|
||||
import { z } from "zod";
|
||||
import z from "zod";
|
||||
|
||||
import app_RoutingForms from "@calcom/app-store/ee/routing-forms/trpc-router";
|
||||
import ethRouter from "@calcom/app-store/rainbow/trpc/router";
|
||||
@@ -493,7 +493,19 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||
},
|
||||
unconfirmed: {
|
||||
endTime: { gte: new Date() },
|
||||
status: { equals: BookingStatus.PENDING },
|
||||
OR: [
|
||||
{
|
||||
AND: [
|
||||
{ NOT: { recurringEventId: { equals: null } } },
|
||||
{
|
||||
status: { equals: BookingStatus.PENDING },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
status: { equals: BookingStatus.PENDING },
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const bookingListingOrderby: Record<
|
||||
@@ -572,7 +584,25 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||
skip,
|
||||
});
|
||||
|
||||
let bookings = bookingsQuery.map((booking) => {
|
||||
const recurringInfo = await prisma.booking.groupBy({
|
||||
by: ["recurringEventId"],
|
||||
_min: {
|
||||
startTime: true,
|
||||
},
|
||||
_count: {
|
||||
recurringEventId: true,
|
||||
},
|
||||
where: {
|
||||
recurringEventId: {
|
||||
not: { equals: null },
|
||||
},
|
||||
status: {
|
||||
notIn: [BookingStatus.CANCELLED],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const bookings = bookingsQuery.map((booking) => {
|
||||
return {
|
||||
...booking,
|
||||
eventType: {
|
||||
@@ -583,26 +613,8 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||
endTime: booking.endTime.toISOString(),
|
||||
};
|
||||
});
|
||||
|
||||
const bookingsFetched = bookings.length;
|
||||
const seenBookings: Record<string, boolean> = {};
|
||||
|
||||
// Remove duplicate recurring bookings for upcoming status.
|
||||
// Couldn't use distinct in query because the distinct column would be different for recurring and non recurring event.
|
||||
// We might be actually sending less then the limit, due to this filter
|
||||
// TODO: Figure out a way to fix it.
|
||||
if (bookingListingByStatus === "upcoming") {
|
||||
bookings = bookings.filter((booking) => {
|
||||
if (!booking.recurringEventId) {
|
||||
return true;
|
||||
}
|
||||
if (seenBookings[booking.recurringEventId]) {
|
||||
return false;
|
||||
}
|
||||
seenBookings[booking.recurringEventId] = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
let nextCursor: typeof skip | null = skip;
|
||||
if (bookingsFetched > take) {
|
||||
nextCursor += bookingsFetched;
|
||||
@@ -612,6 +624,7 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||
|
||||
return {
|
||||
bookings,
|
||||
recurringInfo,
|
||||
nextCursor,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user