chore: migrate api/cancel to App Router (#19074)
* Add app/api/cancel/route.ts * remove pages router api/cancel * refactors needed * refactor
This commit is contained in:
1 parent
c9bfd977b1
commit
e8890156a1
4 files changed
+46
-24
No files matched your search
@@ -140,7 +140,8 @@ async function getBookingToDelete(id: number | undefined, uid: string | undefine
|
||||
|
||||
export type BookingToDelete = Awaited<ReturnType<typeof getBookingToDelete>>;
|
||||
|
||||
export type CustomRequest = NextApiRequest & {
|
||||
export type AppRouterRequest = { appDirRequestBody: unknown };
|
||||
export type CustomRequest = (NextApiRequest | AppRouterRequest) & {
|
||||
userId?: number;
|
||||
bookingToDelete?: BookingToDelete;
|
||||
platformClientId?: string;
|
||||
@@ -159,6 +160,7 @@ export type HandleCancelBookingResponse = {
|
||||
};
|
||||
|
||||
async function handler(req: CustomRequest) {
|
||||
const body = (req as AppRouterRequest).appDirRequestBody ?? (req as NextApiRequest).body;
|
||||
const {
|
||||
id,
|
||||
uid,
|
||||
@@ -168,7 +170,7 @@ async function handler(req: CustomRequest) {
|
||||
cancelledBy,
|
||||
cancelSubsequentBookings,
|
||||
internalNote,
|
||||
} = bookingCancelInput.parse(req.body);
|
||||
} = bookingCancelInput.parse(body);
|
||||
req.bookingToDelete = await getBookingToDelete(id, uid);
|
||||
const {
|
||||
bookingToDelete,
|
||||
@@ -568,7 +570,7 @@ async function handler(req: CustomRequest) {
|
||||
await handleInternalNote({
|
||||
internalNote,
|
||||
booking: bookingToDelete,
|
||||
userId,
|
||||
userId: userId || -1,
|
||||
teamId: teamId,
|
||||
});
|
||||
}
|
||||
@@ -586,7 +588,7 @@ async function handler(req: CustomRequest) {
|
||||
} catch (error) {
|
||||
console.error("Error deleting event", error);
|
||||
}
|
||||
req.statusCode = 200;
|
||||
(req as NextApiRequest).statusCode = 200;
|
||||
return {
|
||||
success: true,
|
||||
message: "Booking successfully cancelled.",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { NextApiRequest } from "next";
|
||||
|
||||
import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
||||
import { updateMeeting } from "@calcom/core/videoClient";
|
||||
import { sendCancelledSeatEmailsAndSMS } from "@calcom/emails";
|
||||
@@ -15,7 +17,7 @@ import { bookingCancelAttendeeSeatSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import type { CustomRequest } from "../../handleCancelBooking";
|
||||
import type { AppRouterRequest, CustomRequest } from "../../handleCancelBooking";
|
||||
|
||||
async function cancelAttendeeSeat(
|
||||
req: CustomRequest,
|
||||
@@ -32,7 +34,8 @@ async function cancelAttendeeSeat(
|
||||
},
|
||||
eventTypeMetadata: EventTypeMetadata
|
||||
) {
|
||||
const input = bookingCancelAttendeeSeatSchema.safeParse(req.body);
|
||||
const body = (req as AppRouterRequest).appDirRequestBody ?? (req as NextApiRequest).body;
|
||||
const input = bookingCancelAttendeeSeatSchema.safeParse(body);
|
||||
const { webhooks, evt, eventTypeInfo } = dataForWebhooks;
|
||||
if (!input.success) return;
|
||||
const { seatReferenceUid } = input.data;
|
||||
@@ -61,7 +64,7 @@ async function cancelAttendeeSeat(
|
||||
},
|
||||
}),
|
||||
]);
|
||||
req.statusCode = 200;
|
||||
(req as NextApiRequest).statusCode = 200;
|
||||
|
||||
const attendee = bookingToDelete?.attendees.find((attendee) => attendee.id === seatReference.attendeeId);
|
||||
|
||||
|
||||
Reference in new issue
Block a user