chore: Couple fixes to improve error reporting (#16895)
* chore: Couple fixes to improve error reporting * tweak: Fix error message * refactor: Use findUniqueOrThrow instead of guard * fix: Broken test, missing ID - suspect it passes because only one record exists * chore: Minor refactor to split ZodEffect from ZodType * fix: Satify typescript
This commit is contained in:
1 parent
4b6a389212
commit
a95729f4a1
9 files changed
+31
-28
No files matched your search
@@ -28,11 +28,7 @@ import prisma, { bookingMinimalSelect } from "@calcom/prisma";
|
||||
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import {
|
||||
bookingMetadataSchema,
|
||||
EventTypeMetaDataSchema,
|
||||
schemaBookingCancelParams,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
import { bookingMetadataSchema, EventTypeMetaDataSchema, bookingCancelInput } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
||||
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
@@ -43,7 +39,7 @@ import cancelAttendeeSeat from "./handleSeats/cancel/cancelAttendeeSeat";
|
||||
const log = logger.getSubLogger({ prefix: ["handleCancelBooking"] });
|
||||
|
||||
async function getBookingToDelete(id: number | undefined, uid: string | undefined) {
|
||||
return await prisma.booking.findUnique({
|
||||
return await prisma.booking.findUniqueOrThrow({
|
||||
where: {
|
||||
id,
|
||||
uid,
|
||||
@@ -160,7 +156,7 @@ export type HandleCancelBookingResponse = {
|
||||
|
||||
async function handler(req: CustomRequest) {
|
||||
const { id, uid, allRemainingBookings, cancellationReason, seatReferenceUid, cancelledBy } =
|
||||
schemaBookingCancelParams.parse(req.body);
|
||||
bookingCancelInput.parse(req.body);
|
||||
req.bookingToDelete = await getBookingToDelete(id, uid);
|
||||
const {
|
||||
bookingToDelete,
|
||||
@@ -172,11 +168,7 @@ async function handler(req: CustomRequest) {
|
||||
arePlatformEmailsEnabled,
|
||||
} = req;
|
||||
|
||||
if (!bookingToDelete || !bookingToDelete.user) {
|
||||
throw new HttpError({ statusCode: 400, message: "Booking not found" });
|
||||
}
|
||||
|
||||
if (!bookingToDelete.userId) {
|
||||
if (!bookingToDelete.userId || !bookingToDelete.user) {
|
||||
throw new HttpError({ statusCode: 400, message: "User not found" });
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import { schemaBookingCancelParams } from "@calcom/prisma/zod-utils";
|
||||
import { bookingCancelAttendeeSeatSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -32,9 +32,10 @@ async function cancelAttendeeSeat(
|
||||
},
|
||||
eventTypeMetadata: EventTypeMetadata
|
||||
) {
|
||||
const { seatReferenceUid } = schemaBookingCancelParams.parse(req.body);
|
||||
const input = bookingCancelAttendeeSeatSchema.safeParse(req.body);
|
||||
const { webhooks, evt, eventTypeInfo } = dataForWebhooks;
|
||||
if (!seatReferenceUid) return;
|
||||
if (!input.success) return;
|
||||
const { seatReferenceUid } = input.data;
|
||||
const bookingToDelete = req.bookingToDelete;
|
||||
if (!bookingToDelete?.attendees.length || bookingToDelete.attendees.length < 2) return;
|
||||
|
||||
|
||||
@@ -2664,6 +2664,7 @@ describe("handleSeats", () => {
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
id: firstBookingId,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
|
||||
Reference in new issue
Block a user