refactor: v2 bookings (#16200)

* chore: version existing bookings as 2024-04-15

* feat: initialize bookings version 2024-08-13

* feat: Create and reschedule booking inputs logic

* feat: create booking

* refactor: create booking response

* feat: reschedule booking

* chore: update language input

* feat: recurring booking

* refactor: add booking status in response

* refactor: recurring bookings

* feat: get booking by uid

* wip: get event types

* feat: fetch by multiple status filters and sort

* feat: fetch by teamId, teamIds, eventTypeId, eventTypeIds

* wip: filter by attendee email

* feat: filter by attendee email

* feat: filter by attendee name

* feat: date range filter

* chore: format get bookings output

* chore: finish main merge

* feat: handle instant bookings

* refactor: separate reschedule endpoint

* feat: cancel endpoint

* feat: mark absent host or attendees

* chore: dont expose metadata for now

* chore: add hostId to response

* fix: metadata

* feat: bill bookings

* feat: cancellationReason

* feat: rescheduling reason

* handle already busy booking error

* test: create new booking

* fix: handleNewRecurringBooking ignoring noEmail

* test: recurring bookings

* test: get individual bookings

* fix: cancel email sent if arePlatformEmailsEnabled=false but platformClientId is undefined

* tests: cancel, reschedule, mark absent

* fix: generateIcsFile null pointer exception

* cancel test

* error msg improve

* tests: team event type creation and teamId, teamIds filters

* test: cancel recurring booking

* refactor: make hosts and attendees an array

* sort by asc start

* simplify

* refactor: absent

* fix: make work with api key

* test

* ts remove any

* feat: BookingUidGuard

* fix: recurring booking no email

* fix: legacy bookings recurring noEmail

* add swagger

* retrigger build

* fix: atom booker work with v2

* docs: exclude old controller from docs

* refactor: make eventTypeIds and teamIds getBookings query params comma separated string

* docs: swagger for get bookings query

* swagger docs

* swagger docs

* docs: document authorization header

* refactor: remove unused attendee variable

* refactor: remove unused check

* refactor: remove unused attendee variable

* refactor: spelling

* use published platform libraries

* fix: ci

* fix: ci

* fix: ci

* fix: ci

* cleanup script platform types

* fix: use libraries from npm

* chore: set test env vapid keys

* fix: event type tests

* fix: remove location from system fields

* fix legacy event types

* Revert "fix legacy event types"

This reverts commit e64b473b73f7ef0fe88942cd87277d29a512b946.

* Revert "fix: remove location from system fields"

This reverts commit bee9a15cb27cd34705f34c427b6b50d51e3b7ee7.

* Revert "fix: event type tests"

This reverts commit fab1cb0f5eeb65e4f542bfbeb83849ceed7ba428.

* update libraries

* fix: increase node space for ci runner

* fix: increase node space for ci runner

* fix: increase node space for ci runner

* readd swagger

* ci

* ci

* refactor: increase idle worker memory jest e2e

* fixup! refactor: increase idle worker memory jest e2e

* fixup! fixup! refactor: increase idle worker memory jest e2e

* refactor: split bookings e2e into smaller e2e files

* fixup! refactor: split bookings e2e into smaller e2e files

* fixup! fixup! refactor: split bookings e2e into smaller e2e files

* fixup! fixup! fixup! refactor: split bookings e2e into smaller e2e files

* fixup! Merge branch 'main' into v2-refactor-bookings

* revert event types service

* fix: remove resetModule, maxWorker 2 jest e2e config

---------

Co-authored-by: Morgan Vernay <[email protected]>
Co-authored-by: Morgan <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-09-23 16:19:25 +03:00
1 parent 3371602e0f
commit 0eabe7f28b
60 files changed
+5021 -857

No files matched your search

@@ -23,7 +23,8 @@ export const getHandler = async ({ ctx, input }: GetOptions) => {
const take = input.limit ?? 10;
const skip = input.cursor ?? 0;
const { prisma, user } = ctx;
const bookingListingByStatus = input.filters.status;
const defaultStatus = "upcoming";
const bookingListingByStatus = [input.filters.status || defaultStatus];
const { bookings, recurringInfo, nextCursor } = await getAllUserBookings({
ctx: { user: { id: user.id, email: user.email }, prisma: prisma },
@@ -68,9 +69,10 @@ export async function getBookings({
take: number;
skip: number;
}) {
// TODO: Fix record typing
const bookingWhereInputFilters: Record<string, Prisma.BookingWhereInput> = {
teamIds: {
const bookingWhereInputFilters: Record<string, Prisma.BookingWhereInput> = {};
if (filters?.teamIds && filters.teamIds.length > 0) {
bookingWhereInputFilters.teamIds = {
AND: [
{
OR: [
@@ -78,7 +80,7 @@ export async function getBookings({
eventType: {
team: {
id: {
in: filters?.teamIds,
in: filters.teamIds,
},
},
},
@@ -88,7 +90,7 @@ export async function getBookings({
parent: {
team: {
id: {
in: filters?.teamIds,
in: filters.teamIds,
},
},
},
@@ -97,8 +99,11 @@ export async function getBookings({
],
},
],
},
userIds: {
};
}
if (filters?.userIds && filters.userIds.length > 0) {
bookingWhereInputFilters.userIds = {
AND: [
{
OR: [
@@ -107,7 +112,7 @@ export async function getBookings({
hosts: {
some: {
userId: {
in: filters?.userIds,
in: filters.userIds,
},
},
},
@@ -115,7 +120,7 @@ export async function getBookings({
},
{
userId: {
in: filters?.userIds,
in: filters.userIds,
},
},
{
@@ -123,7 +128,7 @@ export async function getBookings({
users: {
some: {
id: {
in: filters?.userIds,
in: filters.userIds,
},
},
},
@@ -132,21 +137,24 @@ export async function getBookings({
],
},
],
},
eventTypeIds: {
};
}
if (filters?.eventTypeIds && filters.eventTypeIds.length > 0) {
bookingWhereInputFilters.eventTypeIds = {
AND: [
{
OR: [
{
eventTypeId: {
in: filters?.eventTypeIds,
in: filters.eventTypeIds,
},
},
{
eventType: {
parent: {
id: {
in: filters?.eventTypeIds,
in: filters.eventTypeIds,
},
},
},
@@ -154,8 +162,44 @@ export async function getBookings({
],
},
],
},
};
};
}
if (filters?.attendeeEmail) {
bookingWhereInputFilters.attendeeEmail = {
attendees: {
some: {
email: filters.attendeeEmail.trim(),
},
},
};
}
if (filters?.attendeeName) {
bookingWhereInputFilters.attendeeName = {
attendees: {
some: {
name: filters.attendeeName.trim(),
},
},
};
}
if (filters?.afterStartDate) {
bookingWhereInputFilters.afterStartDate = {
startTime: {
gte: new Date(filters.afterStartDate),
},
};
}
if (filters?.beforeEndDate) {
bookingWhereInputFilters.beforeEndDate = {
endTime: {
lte: new Date(filters.beforeEndDate),
},
};
}
const filtersCombined: Prisma.BookingWhereInput[] = !filters
? []
@@ -192,7 +236,6 @@ export async function getBookings({
},
status: true,
paid: true,
payment: {
select: {
paymentOption: true,
@@ -4,8 +4,12 @@ export const ZGetInputSchema = z.object({
filters: z.object({
teamIds: z.number().array().optional(),
userIds: z.number().array().optional(),
status: z.enum(["upcoming", "recurring", "past", "cancelled", "unconfirmed"]),
status: z.enum(["upcoming", "recurring", "past", "cancelled", "unconfirmed"]).optional(),
eventTypeIds: z.number().array().optional(),
attendeeEmail: z.string().optional(),
attendeeName: z.string().optional(),
afterStartDate: z.string().optional(),
beforeEndDate: z.string().optional(),
}),
limit: z.number().min(1).max(100).nullish(),
cursor: z.number().nullish(), // <-- "cursor" needs to exist when using useInfiniteQuery, but can be any type