{"record":{"id":"c2c8a271b2c2c647","repo":"calcom/cal.diy","slug":"user-with-id-newuserid-was-not-found-in-the-dat","errorCode":null,"errorMessage":"User with id=${newUserId} was not found in the database","messagePattern":"User with id=(.+?) was not found in the database","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"apps/api/v2/src/platform/bookings/2024-08-13/services/bookings.service.ts","lineNumber":1078,"sourceCode":"    }\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 user = await this.usersRepository.findByIdWithProfile(newUserId);\n    if (!user) {\n      throw new NotFoundException(`User with id=${newUserId} was not found in the database`);\n    }\n\n    const platformClientParams = booking.eventTypeId\n      ? await this.platformBookingsService.getOAuthClientParams(booking.eventTypeId)\n      : undefined;\n\n    const emailsEnabled = platformClientParams ? platformClientParams.arePlatformEmailsEnabled : true;\n\n    const profile = this.usersService.getUserMainProfile(user);\n\n    try {\n      await roundRobinManualReassignment({\n        bookingId: booking.id,\n        newUserId,\n        orgId: profile?.organizationId || null,\n        reassignReason: body.reason,\n        reassignedById: reassignedByUser.id,\n        emailsEnabled,","sourceCodeStart":1060,"sourceCodeEnd":1096,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/platform/bookings/2024-08-13/services/bookings.service.ts#L1060-L1096","documentation":"Thrown by reassignBookingToUser after permission checks pass, when usersRepository.findByIdWithProfile(newUserId) returns null. NestJS NotFoundException (HTTP 404) - the target user id supplied in the request body does not exist in the database.","triggerScenarios":"POST reassign-to-user with a newUserId that is mistyped, belongs to another org, or was deleted; passing the user's uuid instead of the numeric id.","commonSituations":"Confusing numeric user id with uuid/username; referencing a user from a different environment; deactivated/deleted users; off-by-one or copy errors in the id.","solutions":["Fetch the booking's hosts via GET /v2/bookings/{uid} and select the newUserId from the returned host list.","Validate the user exists with GET /v2/users or the users endpoint before reassigning.","Ensure the id is the numeric primary key, not a uuid or email.","Confirm the user belongs to the same organization as the event type."],"exampleFix":"// before\nawait apiClient.post(`/v2/bookings/${uid}/reassign-to-user`, { userId: candidateId });\n\n// after\nconst booking = await apiClient.get(`/v2/bookings/${uid}`).then(r => r.data);\nconst hostIds = (booking.hosts ?? []).map(h => h.id);\nif (!hostIds.includes(candidateId)) throw new Error(`${candidateId} is not a host of booking ${uid}`);\nawait apiClient.post(`/v2/bookings/${uid}/reassign-to-user`, { userId: candidateId });","handlingStrategy":"validation","validationCode":"// Only pass a userId that is a real, in-org host of the booking\nconst booking = await apiClient.get(`/v2/bookings/${uid}`).then(r => r.data);\nconst hostIds = (booking.hosts ?? []).map(h => h.id);\nif (!hostIds.includes(newUserId)) {\n  throw new Error(`User ${newUserId} is not a host of booking ${uid}`);\n}","typeGuard":"function isKnownHost(userId: number, booking: { hosts?: Array<{ id: number }> }): boolean {\n  return (booking.hosts ?? []).some(h => h.id === userId);\n}","tryCatchPattern":"try {\n  await apiClient.post(`/v2/bookings/${uid}/reassign-to-user`, { userId: newUserId });\n} catch (err) {\n  if (err.response?.status === 404 && /User with id=.*was not found/i.test(err.response?.data?.message ?? '')) {\n    throw new UserMissingError(newUserId);\n  }\n  throw err;\n}","preventionTips":["Pick the newUserId from the booking's hosts array, never free-typed.","Use the numeric user id, not uuid/email/username.","Re-fetch hosts immediately before the call to avoid staleness."],"tags":["user","not-found","booking","api-v2","reassign","validation"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}