From debef8119ed0395055aa82de633b0a978b91d9a9 Mon Sep 17 00:00:00 2001 From: Mihai C <34626017+mihaic195@users.noreply.github.com> Date: Fri, 5 Nov 2021 00:24:15 +0200 Subject: [PATCH] Rejected bookings should be displayed in cancelled bookings tab (#1100) * fix: rejected bookings should be displayed in cancelled bookings tab * fix: add migration to update status of rejected bookings * unrelated fix Co-authored-by: Alex van Andel --- pages/api/book/confirm.ts | 3 +- .../migration.sql | 1 + server/routers/viewer.tsx | 29 +++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 prisma/migrations/20211101151249_update_rejected_bookings/migration.sql diff --git a/pages/api/book/confirm.ts b/pages/api/book/confirm.ts index d7440d1d..ea35cf83 100644 --- a/pages/api/book/confirm.ts +++ b/pages/api/book/confirm.ts @@ -1,4 +1,4 @@ -import { User, Booking, SchedulingType } from "@prisma/client"; +import { User, Booking, SchedulingType, BookingStatus } from "@prisma/client"; import type { NextApiRequest, NextApiResponse } from "next"; import { refund } from "@ee/lib/stripe/server"; @@ -146,6 +146,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }, data: { rejected: true, + status: BookingStatus.REJECTED, }, }); const attendeeMail = new EventRejectionMail(evt); diff --git a/prisma/migrations/20211101151249_update_rejected_bookings/migration.sql b/prisma/migrations/20211101151249_update_rejected_bookings/migration.sql new file mode 100644 index 00000000..a170caec --- /dev/null +++ b/prisma/migrations/20211101151249_update_rejected_bookings/migration.sql @@ -0,0 +1 @@ +UPDATE "Booking" SET "status" = 'rejected' WHERE "rejected" = TRUE; diff --git a/server/routers/viewer.tsx b/server/routers/viewer.tsx index 17da5519..e366e3eb 100644 --- a/server/routers/viewer.tsx +++ b/server/routers/viewer.tsx @@ -237,9 +237,32 @@ const loggedInViewerRouter = createProtectedRouter() const { prisma, user } = ctx; const bookingListingByStatus = input.status; const bookingListingFilters: Record = { - upcoming: [{ endTime: { gte: new Date() }, NOT: { status: { equals: BookingStatus.CANCELLED } } }], - past: [{ endTime: { lte: new Date() }, NOT: { status: { equals: BookingStatus.CANCELLED } } }], - cancelled: [{ status: { equals: BookingStatus.CANCELLED } }], + upcoming: [ + { + endTime: { gte: new Date() }, + AND: [ + { NOT: { status: { equals: BookingStatus.CANCELLED } } }, + { NOT: { status: { equals: BookingStatus.REJECTED } } }, + ], + }, + ], + past: [ + { + endTime: { lte: new Date() }, + AND: [ + { NOT: { status: { equals: BookingStatus.CANCELLED } } }, + { NOT: { status: { equals: BookingStatus.REJECTED } } }, + ], + }, + ], + cancelled: [ + { + OR: [ + { status: { equals: BookingStatus.CANCELLED } }, + { status: { equals: BookingStatus.REJECTED } }, + ], + }, + ], }; const bookingListingOrderby: Record = { upcoming: { startTime: "desc" },