chore: update status code (#20443)

* chore: update status code

* chore: update status code

* fix: error unhandled
This commit is contained in:
Udit Takkar authored and GitHub committed 2025-04-01 10:08:14 -03:00
1 parent d24a93962f
commit aaa39cccf8
3 files changed
+10 -18

No files matched your search

@@ -570,7 +570,7 @@ async function handler(
dateFrom: dayjs(start).tz(reqBody.timeZone).format(), dateFrom: dayjs(start).tz(reqBody.timeZone).format(),
dateTo: dayjs(end).tz(reqBody.timeZone).format(), dateTo: dayjs(end).tz(reqBody.timeZone).format(),
timeZone: reqBody.timeZone, timeZone: reqBody.timeZone,
originalRescheduledBooking, originalRescheduledBooking: originalRescheduledBooking ?? null,
}, },
loggerWithEventDetails, loggerWithEventDetails,
shouldServeCache shouldServeCache
@@ -5,28 +5,20 @@ import { HttpError } from "@calcom/lib/http-error";
import { BookingRepository } from "@calcom/lib/server/repository/booking"; import { BookingRepository } from "@calcom/lib/server/repository/booking";
import { BookingStatus } from "@calcom/prisma/enums"; import { BookingStatus } from "@calcom/prisma/enums";
export const validateOriginalRescheduledBooking = async ( export async function getOriginalRescheduledBooking(uid: string, seatsEventType?: boolean) {
originalRescheduledBooking: OriginalRescheduledBooking const originalBooking = await BookingRepository.findOriginalRescheduledBooking(uid, seatsEventType);
) => {
if (!originalRescheduledBooking) { if (!originalBooking) {
throw new HttpError({ statusCode: 404, message: "Could not find original booking" }); throw new HttpError({ statusCode: 404, message: "Could not find original booking" });
} }
if ( if (originalBooking.status === BookingStatus.CANCELLED && !originalBooking.rescheduled) {
originalRescheduledBooking.status === BookingStatus.CANCELLED && throw new HttpError({ statusCode: 400, message: ErrorCode.CancelledBookingsCannotBeRescheduled });
!originalRescheduledBooking.rescheduled
) {
throw new HttpError({ statusCode: 403, message: ErrorCode.CancelledBookingsCannotBeRescheduled });
} }
};
export async function getOriginalRescheduledBooking(uid: string, seatsEventType?: boolean) {
const originalBooking = await BookingRepository.findOriginalRescheduledBooking(uid, seatsEventType);
validateOriginalRescheduledBooking(originalBooking);
return originalBooking; return originalBooking;
} }
export type BookingType = Prisma.PromiseReturnType<typeof getOriginalRescheduledBooking>; export type BookingType = Prisma.PromiseReturnType<typeof getOriginalRescheduledBooking> | null;
export type OriginalRescheduledBooking = Awaited<ReturnType<typeof getOriginalRescheduledBooking>>; export type OriginalRescheduledBooking = Awaited<ReturnType<typeof getOriginalRescheduledBooking>> | null;
@@ -95,7 +95,7 @@ function getStatusCode(cause: Error): number {
case ErrorCode.AvailabilityNotFoundInSchedule: case ErrorCode.AvailabilityNotFoundInSchedule:
return 400; return 400;
case ErrorCode.CancelledBookingsCannotBeRescheduled: case ErrorCode.CancelledBookingsCannotBeRescheduled:
return 403; return 400;
case ErrorCode.NoAvailableUsersFound: case ErrorCode.NoAvailableUsersFound:
case ErrorCode.HostsUnavailableForBooking: case ErrorCode.HostsUnavailableForBooking:
case ErrorCode.PaymentCreationFailure: case ErrorCode.PaymentCreationFailure: