* chore: get bookings with kysely * fixup! chore: get bookings with kysely * replace left joins with inner joins * add missing filter and count with kysely * main query done * kysely use connection string * fix attendee emails operator * fix immutability and add attendee email filter * chore: everything working but date filters * limit offset * chore: bump platform libraries * fix bookingseat / attendee user email filter * refactor, clean, and subquery updatedAt/createdAt * fix import kysely types path * fix missing references and payments fields * create kysely module in apiv2 * fix before created at filter * fix types * update yarn.lock * update yarn.lock --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import type { Kysely } from "kysely";
|
|
|
|
import type { TextFilterValue } from "@calcom/features/data-table/lib/types";
|
|
import type { DB } from "@calcom/kysely";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
import { getBookings } from "@calcom/trpc/server/routers/viewer/bookings/get.handler";
|
|
|
|
type InputByStatus = "upcoming" | "recurring" | "past" | "cancelled" | "unconfirmed";
|
|
export type SortOptions = {
|
|
sortStart?: "asc" | "desc";
|
|
sortEnd?: "asc" | "desc";
|
|
sortCreated?: "asc" | "desc";
|
|
sortUpdated?: "asc" | "desc";
|
|
};
|
|
type GetOptions = {
|
|
ctx: {
|
|
user: { id: number; email: string; orgId?: number | null };
|
|
prisma: PrismaClient;
|
|
kysely: Kysely<DB>;
|
|
};
|
|
bookingListingByStatus: InputByStatus[];
|
|
take: number;
|
|
skip: number;
|
|
filters: {
|
|
status?: InputByStatus;
|
|
teamIds?: number[] | undefined;
|
|
userIds?: number[] | undefined;
|
|
eventTypeIds?: number[] | undefined;
|
|
attendeeEmail?: string | TextFilterValue;
|
|
attendeeName?: string | TextFilterValue;
|
|
};
|
|
sort?: SortOptions;
|
|
};
|
|
|
|
const getAllUserBookings = async ({ ctx, filters, bookingListingByStatus, take, skip, sort }: GetOptions) => {
|
|
const { prisma, user, kysely } = ctx;
|
|
|
|
const { bookings, recurringInfo, totalCount } = await getBookings({
|
|
user,
|
|
prisma,
|
|
kysely,
|
|
bookingListingByStatus,
|
|
filters: filters,
|
|
sort,
|
|
take,
|
|
skip,
|
|
});
|
|
|
|
return {
|
|
bookings,
|
|
recurringInfo,
|
|
totalCount,
|
|
};
|
|
};
|
|
|
|
export default getAllUserBookings;
|