* experiment: cold start perf * fix: update failing test * chore: add database indexes * chore: use json protocol and add query batching back * Update [status].tsx * Update [trpc].ts * Delete getSlimSession.ts * Update createContext.ts * remove trpc caller * correctly import Prisma * lazy ethRouter * replace crypto with md5 * import fixes * public event endpoint refactor * Update yarn.lock * Update yarn.lock * Using yarn.lock from main --------- Co-authored-by: Omar López <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Efraín Rochín <[email protected]> Co-authored-by: Keith Williams <[email protected]>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { BookingStatus } from "@prisma/client";
|
|
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
type BookingUnconfirmedCountOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
};
|
|
|
|
export const bookingUnconfirmedCountHandler = async ({ ctx }: BookingUnconfirmedCountOptions) => {
|
|
const { user } = ctx;
|
|
const count = await prisma.booking.count({
|
|
where: {
|
|
status: BookingStatus.PENDING,
|
|
userId: user.id,
|
|
endTime: { gt: new Date() },
|
|
},
|
|
});
|
|
const recurringGrouping = await prisma.booking.groupBy({
|
|
by: ["recurringEventId"],
|
|
_count: {
|
|
recurringEventId: true,
|
|
},
|
|
where: {
|
|
recurringEventId: { not: { equals: null } },
|
|
status: { equals: "PENDING" },
|
|
userId: user.id,
|
|
endTime: { gt: new Date() },
|
|
},
|
|
});
|
|
return recurringGrouping.reduce((prev, current) => {
|
|
// recurringEventId is the total number of recurring instances for a booking
|
|
// we need to subtract all but one, to represent a single recurring booking
|
|
return prev - (current._count?.recurringEventId - 1);
|
|
}, count);
|
|
};
|