mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* 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: [email protected] <[email protected]> * 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>
137 lines
4.1 KiB
TypeScript
137 lines
4.1 KiB
TypeScript
import dayjs from "@calcom/dayjs";
|
|
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
|
import type { EventPayloadType } from "@calcom/features/webhooks/lib/sendPayload";
|
|
import { ErrorCode } from "@calcom/lib/errorCodes";
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
import prisma from "@calcom/prisma";
|
|
import { BookingStatus } from "@calcom/prisma/enums";
|
|
import { createLoggerWithEventDetails } from "../handleNewBooking/logger";
|
|
import createNewSeat from "./create/createNewSeat";
|
|
import rescheduleSeatedBooking from "./reschedule/rescheduleSeatedBooking";
|
|
import type { HandleSeatsResultBooking, NewSeatedBookingObject, SeatedBooking } from "./types";
|
|
|
|
const handleSeats = async (
|
|
newSeatedBookingObject: NewSeatedBookingObject
|
|
) => {
|
|
const {
|
|
eventType,
|
|
reqBodyUser,
|
|
rescheduleUid,
|
|
reqBookingUid,
|
|
invitee,
|
|
bookerEmail,
|
|
smsReminderNumber,
|
|
eventTypeInfo,
|
|
uid,
|
|
originalRescheduledBooking,
|
|
reqBodyMetadata,
|
|
eventTypeId,
|
|
subscriberOptions,
|
|
eventTrigger,
|
|
evt,
|
|
rescheduledBy,
|
|
isDryRun = false,
|
|
fullName,
|
|
traceContext,
|
|
} = newSeatedBookingObject;
|
|
// TODO: We could allow doing more things to support good dry run for seats
|
|
if (isDryRun) return;
|
|
const loggerWithEventDetails = createLoggerWithEventDetails(eventType.id, reqBodyUser, eventType.slug);
|
|
|
|
let resultBooking: HandleSeatsResultBooking = null;
|
|
|
|
const seatedBooking: SeatedBooking | null = await prisma.booking.findFirst({
|
|
where: {
|
|
OR: [
|
|
{
|
|
uid: rescheduleUid || reqBookingUid,
|
|
},
|
|
|
|
{
|
|
eventTypeId: eventType.id,
|
|
startTime: new Date(evt.startTime),
|
|
},
|
|
],
|
|
status: BookingStatus.ACCEPTED,
|
|
},
|
|
select: {
|
|
uid: true,
|
|
id: true,
|
|
attendees: { include: { bookingSeat: true } },
|
|
userId: true,
|
|
references: true,
|
|
startTime: true,
|
|
user: true,
|
|
status: true,
|
|
smsReminderNumber: true,
|
|
endTime: true,
|
|
},
|
|
});
|
|
|
|
if (!seatedBooking && rescheduleUid) {
|
|
throw new HttpError({ statusCode: 404, message: ErrorCode.BookingNotFound });
|
|
}
|
|
|
|
// We might be trying to create a new booking
|
|
if (!seatedBooking) {
|
|
return;
|
|
}
|
|
|
|
// See if attendee is already signed up for timeslot
|
|
if (
|
|
seatedBooking.attendees.find((attendee) => {
|
|
return attendee.email === invitee[0].email;
|
|
}) &&
|
|
dayjs.utc(seatedBooking.startTime).format() === evt.startTime
|
|
) {
|
|
throw new HttpError({ statusCode: 409, message: ErrorCode.AlreadySignedUpForBooking });
|
|
}
|
|
|
|
// There are two paths here, reschedule a booking with seats and booking seats without reschedule
|
|
if (rescheduleUid) {
|
|
resultBooking = await rescheduleSeatedBooking(
|
|
// Assert that the rescheduleUid is defined
|
|
{ ...newSeatedBookingObject, rescheduleUid },
|
|
seatedBooking,
|
|
resultBooking,
|
|
loggerWithEventDetails
|
|
);
|
|
} else {
|
|
resultBooking = await createNewSeat(newSeatedBookingObject, seatedBooking, reqBodyMetadata);
|
|
}
|
|
|
|
// If the resultBooking is defined we should trigger webhooks else, trigger in handleNewBooking
|
|
if (resultBooking) {
|
|
const metadata = {
|
|
...(typeof resultBooking.metadata === "object" && resultBooking.metadata),
|
|
...reqBodyMetadata,
|
|
};
|
|
|
|
const webhookData: EventPayloadType = {
|
|
...evt,
|
|
...eventTypeInfo,
|
|
uid: resultBooking?.uid || uid,
|
|
bookingId: seatedBooking?.id,
|
|
attendeeSeatId: resultBooking?.seatReferenceUid,
|
|
rescheduleUid,
|
|
rescheduleStartTime: originalRescheduledBooking?.startTime
|
|
? dayjs(originalRescheduledBooking?.startTime).utc().format()
|
|
: undefined,
|
|
rescheduleEndTime: originalRescheduledBooking?.endTime
|
|
? dayjs(originalRescheduledBooking?.endTime).utc().format()
|
|
: undefined,
|
|
metadata,
|
|
eventTypeId,
|
|
status: "ACCEPTED",
|
|
smsReminderNumber: invitee[0]?.phoneNumber || smsReminderNumber || undefined,
|
|
rescheduledBy,
|
|
};
|
|
|
|
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData, isDryRun, traceContext });
|
|
}
|
|
|
|
return resultBooking;
|
|
};
|
|
|
|
export default handleSeats;
|