Files
calendar/apps/web/lib/booking.ts
T
Benny JooGitHubbenny@cal.com <sldisek783@gmail.com>Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ab21c7f805 refactor: Cal.diy (#28903)
* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com

This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main:

- Rebrand Cal.com to Cal.diy across the entire codebase
- Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions
- Switch license from AGPL-3.0 to MIT
- Remove docs/ directory (migrated to Nextra at cal.diy)
- Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc.
- Clean up .env.example for self-hosted Cal.diy
- Update Docker image references to calcom/cal.diy
- Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork
- Add PR welcome bot for Cal.diy contributors
- Fix API v2 breaking changes oasdiff ignore entries
- Replace Blacksmith CI runners with default GitHub Actions

3893 files changed, 20789 insertions(+), 411020 deletions(-)

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* rip out org related comments in api v2

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-04-15 09:52:36 -03:00

238 lines
5.9 KiB
TypeScript

import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
import { bookingResponsesDbSchema } from "@calcom/features/bookings/lib/getBookingResponsesSchema";
import prisma from "@calcom/prisma";
import type { Prisma } from "@calcom/prisma/client";
import { BookingStatus } from "@calcom/prisma/enums";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
export const getEventTypesFromDB = async (id: number) => {
const userSelect = {
id: true,
name: true,
username: true,
hideBranding: true,
theme: true,
brandColor: true,
darkBrandColor: true,
email: true,
timeZone: true,
isPlatformManaged: true,
};
const eventType = await prisma.eventType.findUnique({
where: {
id,
},
select: {
id: true,
title: true,
description: true,
interfaceLanguage: true,
length: true,
eventName: true,
recurringEvent: true,
requiresConfirmation: true,
canSendCalVideoTranscriptionEmails: true,
userId: true,
successRedirectUrl: true,
customInputs: true,
locations: true,
price: true,
currency: true,
bookingFields: true,
allowReschedulingPastBookings: true,
hideOrganizerEmail: true,
disableCancelling: true,
disableRescheduling: true,
requiresCancellationReason: true,
minimumRescheduleNotice: true,
disableGuests: true,
timeZone: true,
profile: {
select: {
organizationId: true,
organization: {
select: {
brandColor: true,
darkBrandColor: true,
theme: true,
},
},
},
},
teamId: true,
owner: {
select: userSelect,
},
users: {
select: userSelect,
},
hosts: {
select: {
user: {
select: userSelect,
},
},
},
team: {
select: {
id: true,
slug: true,
name: true,
hideBranding: true,
brandColor: true,
darkBrandColor: true,
theme: true,
parent: {
select: {
hideBranding: true,
brandColor: true,
darkBrandColor: true,
theme: true,
},
},
createdByOAuthClientId: true,
},
},
metadata: true,
seatsPerTimeSlot: true,
seatsShowAttendees: true,
seatsShowAvailabilityCount: true,
schedulingType: true,
periodStartDate: true,
periodEndDate: true,
parent: {
select: {
teamId: true,
team: {
select: {
hideBranding: true,
parent: {
select: {
hideBranding: true,
},
},
},
},
},
},
},
});
if (!eventType) {
return eventType;
}
const metadata = EventTypeMetaDataSchema.parse(eventType.metadata);
const isOrgTeamEvent = !!eventType?.team && !!eventType.profile?.organizationId;
return {
isDynamic: false,
...eventType,
bookingFields: getBookingFieldsWithSystemFields({ ...eventType, isOrgTeamEvent }),
metadata,
};
};
export const handleSeatsEventTypeOnBooking = async (
eventType: {
seatsPerTimeSlot?: number | null;
seatsShowAttendees: boolean | null;
seatsShowAvailabilityCount: boolean | null;
[x: string | number | symbol]: unknown;
},
bookingInfo: Partial<
Prisma.BookingGetPayload<{
include: {
attendees: { select: { name: true; email: true; phoneNumber: true } };
seatsReferences: { select: { referenceUid: true } };
user: {
select: {
id: true;
name: true;
email: true;
username: true;
timeZone: true;
};
};
};
}>
>,
seatReferenceUid?: string,
isHost?: boolean
) => {
bookingInfo.responses = {};
type seatAttendee = {
attendee: {
email: string;
name: string;
phoneNumber: string | null;
};
id: number;
data: Prisma.JsonValue;
bookingId: number;
attendeeId: number;
referenceUid: string;
} | null;
let seatAttendee: seatAttendee = null;
if (seatReferenceUid) {
seatAttendee = await prisma.bookingSeat.findUnique({
where: {
referenceUid: seatReferenceUid,
},
include: {
attendee: {
select: {
name: true,
email: true,
phoneNumber: true,
},
},
},
});
}
if (seatAttendee) {
const seatAttendeeData = seatAttendee.data as unknown as {
description?: string;
responses: Prisma.JsonValue;
};
bookingInfo.description = seatAttendeeData.description ?? null;
bookingInfo.responses = bookingResponsesDbSchema.parse(seatAttendeeData.responses ?? {});
}
if (!eventType.seatsShowAttendees && !isHost) {
if (seatAttendee) {
const attendee = bookingInfo?.attendees?.find((a) => {
return (
a.email === seatAttendee?.attendee?.email ||
(a.phoneNumber && a.phoneNumber === seatAttendee?.attendee?.phoneNumber)
);
});
bookingInfo.attendees = attendee ? [attendee] : [];
} else {
bookingInfo.attendees = [];
}
}
// // @TODO: If handling teams, we need to do more check ups for this.
// if (bookingInfo?.user?.id === userId) {
// return;
// }
return bookingInfo;
};
export async function getRecurringBookings(recurringEventId: string | null) {
if (!recurringEventId) return null;
const recurringBookings = await prisma.booking.findMany({
where: {
recurringEventId,
status: {
in: [BookingStatus.ACCEPTED, BookingStatus.PENDING],
},
},
select: {
startTime: true,
},
});
return recurringBookings.map((obj) => obj.startTime.toString());
}