{"record":{"id":"dde69f4129aef334","repo":"calcom/cal.diy","slug":"event-type-with-id-booking-eventtypeid-was-not","errorCode":null,"errorMessage":"Event type with id=${booking.eventTypeId} was not found in the database","messagePattern":"Event type with id=(.+?) was not found in the database","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apps/api/v2/src/platform/bookings/2024-08-13/services/bookings.service.ts","lineNumber":1000,"sourceCode":"    if (!booking) {\n      throw new Error(`Booking with uid=${bookingUid} was not found in the database`);\n    }\n\n    const isRecurring = !!booking.recurringEventId;\n    if (isRecurring) {\n      return this.outputService.getOutputRecurringBooking(booking);\n    }\n    return this.outputService.getOutputBooking(booking);\n  }\n\n  async reassignBooking(bookingUid: string, reassignedByUser: ApiAuthGuardUser) {\n    const booking = await this.bookingsRepository.getByUidWithEventType(bookingUid);\n    if (!booking) {\n      throw new NotFoundException(`Booking with uid=${bookingUid} was not found in the database`);\n    }\n\n    if (!booking.eventType) {\n      throw new BadRequestException(\n        `Event type with id=${booking.eventTypeId} was not found in the database`\n      );\n    }\n\n    const isAllowed = await this.eventTypeAccessService.userIsEventTypeAdminOrOwner(\n      reassignedByUser,\n      booking.eventType\n    );\n\n    if (!isAllowed) {\n      throw new ForbiddenException(BOOKING_REASSIGN_PERMISSION_ERROR);\n    }\n\n    const platformClientParams = booking.eventTypeId\n      ? await this.platformBookingsService.getOAuthClientParams(booking.eventTypeId)\n      : undefined;\n\n    const emailsEnabled = platformClientParams ? platformClientParams.arePlatformEmailsEnabled : true;","sourceCodeStart":982,"sourceCodeEnd":1018,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/platform/bookings/2024-08-13/services/bookings.service.ts#L982-L1018","documentation":"Thrown by BookingsService.reassignBooking when the booking row loaded via getByUidWithEventType exists but its eventType relation is null (the eventTypeId foreign key points to a missing/deleted event type). It is a NestJS BadRequestException (HTTP 400) because reassignment logic depends on event-type metadata (hosts, scheduling) that cannot be reconstructed. The check is `if (!booking.eventType)` immediately after the booking lookup, so a null relation trips it even when eventTypeId is set.","triggerScenarios":"POST to the reassign-booking endpoint with a bookingUid whose event type record was deleted or whose eventType relation was not selected by the repository query; a booking created by an integration that never wrote a matching EventType row.","commonSituations":"Orphaned bookings left after an event type was hard-deleted; staging/test databases with partial imports where bookings exist without their event types; multi-org setups where the event type lives in a different org scope than the booking.","solutions":["Verify the booking and its event type with GET /v2/bookings/{bookingUid} before calling reassign, and confirm the response includes a non-null eventTypeId/eventType.","If the event type was deleted, restore it or recreate it with the same id, then retry the reassign call.","If the data is inconsistent, ask a DB admin to reconcile the booking.eventTypeId or remove the orphaned booking.","Guard the caller so it never attempts reassign on bookings whose eventType is missing."],"exampleFix":"// before\nawait apiClient.post(`/v2/bookings/${uid}/reassign`);\n\n// after\nconst booking = await apiClient.get(`/v2/bookings/${uid}`).then(r => r.data);\nif (!booking.eventTypeId || !booking.eventType) {\n  throw new Error(`Cannot reassign booking ${uid}: it has no event type (was it deleted?)`);\n}\nawait apiClient.post(`/v2/bookings/${uid}/reassign`);","handlingStrategy":"validation","validationCode":"// Pre-flight: ensure the booking has a resolvable event type before reassign\nconst booking = await apiClient.get(`/v2/bookings/${bookingUid}`).then(r => r.data);\nif (!booking) throw new Error(`Booking ${bookingUid} not found`);\nif (!booking.eventTypeId || !booking.eventType) {\n  throw new Error(`Booking ${bookingUid} has no event type - reassign is not possible`);\n}","typeGuard":"function hasEventType(b: { eventTypeId?: number | null; eventType?: unknown | null }): b is { eventTypeId: number; eventType: NonNullable<typeof b.eventType> } {\n  return b.eventTypeId != null && b.eventType != null;\n}","tryCatchPattern":"try {\n  await apiClient.post(`/v2/bookings/${uid}/reassign`);\n} catch (err) {\n  if (err.response?.status === 400 && /event type.*not found/i.test(err.response?.data?.message ?? '')) {\n    throw new ReassignSkippedError(`Orphaned booking ${uid} - event type missing`);\n  }\n  throw err;\n}","preventionTips":["Never hard-delete event types that still have bookings; soft-delete or audit first.","Validate booking.eventType presence in any workflow that selects reassign candidates.","Run a periodic job to detect orphaned bookings (eventTypeId set, EventType missing)."],"tags":["booking","event-type","data-integrity","api-v2","reassign"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}