refactor: v2 booking locations (#19613)
* refactor: v2 booking locations * regenerate docs * remove describe only * update docs * tests * tests * remove as any * fix tests * log * remove unused dependency * fix: bookings module dependency * fix test * fix: allow all integrations as booking location * refactor: add organizersDefaultApp * refactor: handle all integrations
This commit is contained in:
1 parent
e20df1e7aa
commit
a31242cdc5
11 files changed
+6998
-114
No files matched your search
@@ -38,7 +38,7 @@
|
||||
"@axiomhq/winston": "^1.2.0",
|
||||
"@calcom/platform-constants": "*",
|
||||
"@calcom/platform-enums": "*",
|
||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]7",
|
||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]9",
|
||||
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
|
||||
"@calcom/platform-types": "*",
|
||||
"@calcom/platform-utils": "*",
|
||||
|
||||
@@ -40,6 +40,8 @@ import {
|
||||
import { PlatformOAuthClient, Team } from "@calcom/prisma/client";
|
||||
|
||||
describe("Bookings Endpoints 2024-08-13", () => {
|
||||
const googleMeetUrl = "https://meet.google.com/abc-def-ghi";
|
||||
|
||||
describe("Seated bookings", () => {
|
||||
let app: INestApplication;
|
||||
let organization: Team;
|
||||
@@ -330,7 +332,7 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: "https://meet.google.com/abc-def-ghi",
|
||||
location: googleMeetUrl,
|
||||
bookingFieldsResponses: {
|
||||
codingLanguage: "TypeScript",
|
||||
},
|
||||
@@ -383,6 +385,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: body.attendee.name,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: body.metadata,
|
||||
});
|
||||
@@ -418,6 +424,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: body.attendee.name,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: body.metadata,
|
||||
});
|
||||
@@ -797,7 +807,7 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: "https://meet.google.com/abc-def-ghi",
|
||||
location: googleMeetUrl,
|
||||
bookingFieldsResponses: {
|
||||
codingLanguage: "TypeScript",
|
||||
},
|
||||
@@ -850,6 +860,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: body.attendee.name,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: body.metadata,
|
||||
});
|
||||
@@ -885,6 +899,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: body.attendee.name,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: body.metadata,
|
||||
});
|
||||
@@ -910,7 +928,7 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: "https://meet.google.com/abc-def-ghi",
|
||||
location: googleMeetUrl,
|
||||
bookingFieldsResponses: {
|
||||
codingLanguage: "TypeScript",
|
||||
},
|
||||
@@ -966,6 +984,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: nameAttendeeOne,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: createdRecurringSeatedBooking[0].attendees[0].metadata,
|
||||
});
|
||||
@@ -982,6 +1004,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: nameAttendeeTwo,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: body.metadata,
|
||||
});
|
||||
@@ -1017,6 +1043,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: nameAttendeeOne,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: createdRecurringSeatedBooking[0].attendees[0].metadata,
|
||||
});
|
||||
@@ -1030,6 +1060,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
bookingFieldsResponses: {
|
||||
name: nameAttendeeTwo,
|
||||
...body.bookingFieldsResponses,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
},
|
||||
metadata: body.metadata,
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { CancelBookingOutput_2024_08_13 } from "@/ee/bookings/2024-08-13/outputs
|
||||
import { CreateBookingOutput_2024_08_13 } from "@/ee/bookings/2024-08-13/outputs/create-booking.output";
|
||||
import { MarkAbsentBookingOutput_2024_08_13 } from "@/ee/bookings/2024-08-13/outputs/mark-absent.output";
|
||||
import { RescheduleBookingOutput_2024_08_13 } from "@/ee/bookings/2024-08-13/outputs/reschedule-booking.output";
|
||||
import { CreateEventTypeOutput_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/outputs/create-event-type.output";
|
||||
import { CreateScheduleInput_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/inputs/create-schedule.input";
|
||||
import { SchedulesModule_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/schedules.module";
|
||||
import { SchedulesService_2024_04_15 } from "@/ee/schedules/schedules_2024_04_15/services/schedules.service";
|
||||
@@ -27,10 +28,12 @@ import { withApiAuth } from "test/utils/withApiAuth";
|
||||
import {
|
||||
CAL_API_VERSION_HEADER,
|
||||
SUCCESS_STATUS,
|
||||
VERSION_2024_06_14,
|
||||
VERSION_2024_08_13,
|
||||
X_CAL_CLIENT_ID,
|
||||
} from "@calcom/platform-constants";
|
||||
import {
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
GetBookingOutput_2024_08_13,
|
||||
GetBookingsOutput_2024_08_13,
|
||||
GetSeatedBookingOutput_2024_08_13,
|
||||
@@ -95,6 +98,7 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
|
||||
organization = await teamRepositoryFixture.create({
|
||||
name: `user-bookings-organization-${randomString()}`,
|
||||
isOrganization: true,
|
||||
});
|
||||
oAuthClient = await createOAuthClient(organization.id);
|
||||
|
||||
@@ -146,7 +150,7 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
startTime: new Date(Date.UTC(2020, 0, 8, 13, 0, 0)),
|
||||
endTime: new Date(Date.UTC(2020, 0, 8, 14, 0, 0)),
|
||||
title: "peer coding lets goo",
|
||||
uid: "booking-in-the-past",
|
||||
uid: `booking-in-the-past-${randomString()}`,
|
||||
eventType: {
|
||||
connect: {
|
||||
id: eventTypeId,
|
||||
@@ -326,6 +330,7 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
});
|
||||
|
||||
it("should create a booking", async () => {
|
||||
const googleMeetUrl = "https://meet.google.com/abc-def-ghi";
|
||||
const body: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2030, 0, 8, 13, 0, 0)).toISOString(),
|
||||
eventTypeId,
|
||||
@@ -335,7 +340,7 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: "https://meet.google.com/abc-def-ghi",
|
||||
location: googleMeetUrl,
|
||||
bookingFieldsResponses: {
|
||||
customField: "customValue",
|
||||
},
|
||||
@@ -389,6 +394,10 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
email: body.attendee.email,
|
||||
...body.bookingFieldsResponses,
|
||||
guests: body.guests,
|
||||
location: {
|
||||
optionValue: googleMeetUrl,
|
||||
value: "link",
|
||||
},
|
||||
});
|
||||
expect(data.guests).toEqual(body.guests);
|
||||
|
||||
@@ -1537,6 +1546,351 @@ describe("Bookings Endpoints 2024-08-13", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("booking location", () => {
|
||||
const address = "123 Main St";
|
||||
const link = "https://cal.com/join/123456";
|
||||
const phone = "+37121999999";
|
||||
|
||||
let eventTypeWithAllLocationsId: number;
|
||||
it("can create event type with all locations except google meet", async () => {
|
||||
const eventTypeBody: CreateEventTypeInput_2024_06_14 = {
|
||||
title: "book using any location",
|
||||
slug: "book-using-any-location",
|
||||
lengthInMinutes: 15,
|
||||
locations: [
|
||||
{
|
||||
type: "integration",
|
||||
integration: "cal-video",
|
||||
},
|
||||
{
|
||||
type: "address",
|
||||
address,
|
||||
public: true,
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
link,
|
||||
public: true,
|
||||
},
|
||||
{
|
||||
type: "phone",
|
||||
phone,
|
||||
public: true,
|
||||
},
|
||||
{
|
||||
type: "attendeeAddress",
|
||||
},
|
||||
{
|
||||
type: "attendeePhone",
|
||||
},
|
||||
{
|
||||
type: "attendeeDefined",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const eventTypeResponse = await request(app.getHttpServer())
|
||||
.post("/api/v2/event-types")
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
|
||||
.send(eventTypeBody)
|
||||
.expect(201);
|
||||
const eventTypeResponseBody: CreateEventTypeOutput_2024_06_14 = eventTypeResponse.body;
|
||||
const createdEventType = eventTypeResponseBody.data;
|
||||
expect(createdEventType).toHaveProperty("id");
|
||||
expect(createdEventType.locations).toHaveLength(7);
|
||||
expect(createdEventType.locations).toEqual(createdEventType.locations);
|
||||
eventTypeWithAllLocationsId = createdEventType.id;
|
||||
});
|
||||
|
||||
it("can book with cal video location", async () => {
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "integration",
|
||||
integration: "cal-video",
|
||||
},
|
||||
};
|
||||
|
||||
const bookingResponse = await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(201);
|
||||
|
||||
const bookingResponseBody: CreateBookingOutput_2024_08_13 = bookingResponse.body;
|
||||
const createdBooking = bookingResponseBody.data;
|
||||
expect(createdBooking).toHaveProperty("id");
|
||||
|
||||
if (responseDataIsBooking(createdBooking)) {
|
||||
expect(
|
||||
createdBooking.location?.startsWith("http") || createdBooking.location === "integrations:daily"
|
||||
).toEqual(true);
|
||||
await bookingsRepositoryFixture.deleteById(createdBooking.id);
|
||||
} else {
|
||||
throw new Error("Unexpected response data type");
|
||||
}
|
||||
});
|
||||
|
||||
it("can book with address location", async () => {
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "address",
|
||||
},
|
||||
};
|
||||
|
||||
const bookingResponse = await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(201);
|
||||
|
||||
const bookingResponseBody: CreateBookingOutput_2024_08_13 = bookingResponse.body;
|
||||
const createdBooking = bookingResponseBody.data;
|
||||
expect(createdBooking).toHaveProperty("id");
|
||||
|
||||
if (responseDataIsBooking(createdBooking)) {
|
||||
expect(createdBooking.location).toEqual(address);
|
||||
await bookingsRepositoryFixture.deleteById(createdBooking.id);
|
||||
} else {
|
||||
throw new Error("Unexpected response data type");
|
||||
}
|
||||
});
|
||||
|
||||
it("can book with link location", async () => {
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "link",
|
||||
},
|
||||
};
|
||||
|
||||
const bookingResponse = await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(201);
|
||||
|
||||
const bookingResponseBody: CreateBookingOutput_2024_08_13 = bookingResponse.body;
|
||||
const createdBooking = bookingResponseBody.data;
|
||||
expect(createdBooking).toHaveProperty("id");
|
||||
|
||||
if (responseDataIsBooking(createdBooking)) {
|
||||
expect(createdBooking.location).toEqual(link);
|
||||
await bookingsRepositoryFixture.deleteById(createdBooking.id);
|
||||
} else {
|
||||
throw new Error("Unexpected response data type");
|
||||
}
|
||||
});
|
||||
|
||||
it("can book with link location", async () => {
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "phone",
|
||||
},
|
||||
};
|
||||
|
||||
const bookingResponse = await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(201);
|
||||
|
||||
const bookingResponseBody: CreateBookingOutput_2024_08_13 = bookingResponse.body;
|
||||
const createdBooking = bookingResponseBody.data;
|
||||
expect(createdBooking).toHaveProperty("id");
|
||||
|
||||
if (responseDataIsBooking(createdBooking)) {
|
||||
expect(createdBooking.location).toEqual(phone);
|
||||
await bookingsRepositoryFixture.deleteById(createdBooking.id);
|
||||
} else {
|
||||
throw new Error("Unexpected response data type");
|
||||
}
|
||||
});
|
||||
|
||||
it("can book with attendeeAddress location", async () => {
|
||||
const attendeeAddress = "123 Example St, City, Valhalla";
|
||||
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "attendeeAddress",
|
||||
address: attendeeAddress,
|
||||
},
|
||||
};
|
||||
|
||||
const bookingResponse = await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(201);
|
||||
|
||||
const bookingResponseBody: CreateBookingOutput_2024_08_13 = bookingResponse.body;
|
||||
const createdBooking = bookingResponseBody.data;
|
||||
expect(createdBooking).toHaveProperty("id");
|
||||
|
||||
if (responseDataIsBooking(createdBooking)) {
|
||||
expect(createdBooking.location).toEqual(attendeeAddress);
|
||||
await bookingsRepositoryFixture.deleteById(createdBooking.id);
|
||||
} else {
|
||||
throw new Error("Unexpected response data type");
|
||||
}
|
||||
});
|
||||
|
||||
xit("can book with attendeeAddress location", async () => {
|
||||
const attendeePhone = "+37120993151";
|
||||
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "attendeePhone",
|
||||
phone: attendeePhone,
|
||||
},
|
||||
};
|
||||
|
||||
const bookingResponse = await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(201);
|
||||
|
||||
const bookingResponseBody: CreateBookingOutput_2024_08_13 = bookingResponse.body;
|
||||
const createdBooking = bookingResponseBody.data;
|
||||
expect(createdBooking).toHaveProperty("id");
|
||||
|
||||
if (responseDataIsBooking(createdBooking)) {
|
||||
expect(createdBooking.location).toEqual(attendeePhone);
|
||||
await bookingsRepositoryFixture.deleteById(createdBooking.id);
|
||||
} else {
|
||||
throw new Error("Unexpected response data type");
|
||||
}
|
||||
});
|
||||
|
||||
it("can book with attendeeDefined location", async () => {
|
||||
const attendeeDefinedLocation = "namek 100";
|
||||
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "attendeeDefined",
|
||||
location: attendeeDefinedLocation,
|
||||
},
|
||||
};
|
||||
|
||||
const bookingResponse = await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(201);
|
||||
|
||||
const bookingResponseBody: CreateBookingOutput_2024_08_13 = bookingResponse.body;
|
||||
const createdBooking = bookingResponseBody.data;
|
||||
expect(createdBooking).toHaveProperty("id");
|
||||
|
||||
if (responseDataIsBooking(createdBooking)) {
|
||||
expect(createdBooking.location).toEqual(attendeeDefinedLocation);
|
||||
await bookingsRepositoryFixture.deleteById(createdBooking.id);
|
||||
} else {
|
||||
throw new Error("Unexpected response data type");
|
||||
}
|
||||
});
|
||||
|
||||
it("can't book with not location that is not in event type", async () => {
|
||||
const bookingBody: CreateBookingInput_2024_08_13 = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "integration",
|
||||
integration: "google-meet",
|
||||
},
|
||||
};
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it("can't book with invalid location type", async () => {
|
||||
const bookingBody = {
|
||||
start: new Date(Date.UTC(2040, 0, 9, 13, 0, 0)).toISOString(),
|
||||
eventTypeId: eventTypeWithAllLocationsId,
|
||||
attendee: {
|
||||
name: "Mr Proper",
|
||||
email: "[email protected]",
|
||||
timeZone: "Europe/Rome",
|
||||
language: "it",
|
||||
},
|
||||
location: {
|
||||
type: "blablabala",
|
||||
},
|
||||
};
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post("/v2/bookings")
|
||||
.send(bookingBody)
|
||||
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
|
||||
.expect(400);
|
||||
});
|
||||
});
|
||||
|
||||
function responseDataIsRecurranceBooking(data: any): data is RecurringBookingOutput_2024_08_13 {
|
||||
return (
|
||||
!Array.isArray(data) &&
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from "@/ee/bookings/2024-08-13/services/output.service";
|
||||
import { PlatformBookingsService } from "@/ee/bookings/shared/platform-bookings.service";
|
||||
import { EventTypesRepository_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/event-types.repository";
|
||||
import { OutputEventTypesService_2024_06_14 } from "@/ee/event-types/event-types_2024_06_14/services/output-event-types.service";
|
||||
import { hashAPIKey, isApiKey, stripApiKey } from "@/lib/api-key";
|
||||
import { ApiKeysRepository } from "@/modules/api-keys/api-keys-repository";
|
||||
import { BookingSeatRepository } from "@/modules/booking-seat/booking-seat.repository";
|
||||
@@ -15,13 +16,17 @@ import { BadRequestException, Injectable, NotFoundException } from "@nestjs/comm
|
||||
import { Logger } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { CreationSource } from "@prisma/client";
|
||||
import { isURL, isPhoneNumber } from "class-validator";
|
||||
import { Request } from "express";
|
||||
import { DateTime } from "luxon";
|
||||
import { NextApiRequest } from "next/types";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { z } from "zod";
|
||||
|
||||
import { EventTypeMetaDataSchema } from "@calcom/platform-libraries/event-types";
|
||||
import {
|
||||
EventTypeMetaDataSchema,
|
||||
apiToInternalintegrationsMapping,
|
||||
} from "@calcom/platform-libraries/event-types";
|
||||
import {
|
||||
CancelBookingInput,
|
||||
CancelBookingInput_2024_08_13,
|
||||
@@ -35,7 +40,8 @@ import {
|
||||
RescheduleBookingInput_2024_08_13,
|
||||
RescheduleSeatedBookingInput_2024_08_13,
|
||||
} from "@calcom/platform-types";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import { BookingInputLocation_2024_08_13 } from "@calcom/platform-types/bookings/2024-08-13/inputs/location.input";
|
||||
import { EventType, PlatformOAuthClient } from "@calcom/prisma/client";
|
||||
|
||||
type BookingRequest = NextApiRequest & { userId: number | undefined } & OAuthRequestParams;
|
||||
|
||||
@@ -77,6 +83,7 @@ export class InputBookingsService_2024_08_13 {
|
||||
private readonly config: ConfigService,
|
||||
private readonly apiKeyRepository: ApiKeysRepository,
|
||||
private readonly bookingSeatRepository: BookingSeatRepository,
|
||||
private readonly outputEventTypesService: OutputEventTypesService_2024_06_14,
|
||||
private readonly platformBookingsService: PlatformBookingsService,
|
||||
private readonly usersRepository: UsersRepository
|
||||
) {}
|
||||
@@ -91,23 +98,21 @@ export class InputBookingsService_2024_08_13 {
|
||||
const newRequest = { ...request };
|
||||
const userId = (await this.createBookingRequestOwnerId(request)) ?? undefined;
|
||||
|
||||
const location = request.body.location || request.body.meetingUrl;
|
||||
this.logger.log(`createBookingRequest_2024_04_15`, {
|
||||
this.logger.log(`createBookingRequest_2024_08_13`, {
|
||||
requestId: request.get("X-Request-Id"),
|
||||
ownerId: userId,
|
||||
location,
|
||||
oAuthClientParams,
|
||||
});
|
||||
|
||||
if (oAuthClientParams) {
|
||||
Object.assign(newRequest, { userId, ...oAuthClientParams, platformBookingLocation: location });
|
||||
Object.assign(newRequest, { userId, ...oAuthClientParams });
|
||||
newRequest.body = {
|
||||
...bodyTransformed,
|
||||
noEmail: !oAuthClientParams.arePlatformEmailsEnabled,
|
||||
creationSource: CreationSource.API_V2,
|
||||
};
|
||||
} else {
|
||||
Object.assign(newRequest, { userId, platformBookingLocation: location });
|
||||
Object.assign(newRequest, { userId });
|
||||
newRequest.body = { ...bodyTransformed, noEmail: false, creationSource: CreationSource.API_V2 };
|
||||
}
|
||||
|
||||
@@ -143,6 +148,10 @@ export class InputBookingsService_2024_08_13 {
|
||||
)
|
||||
: inputBooking.attendee.email;
|
||||
|
||||
const inputLocation = inputBooking.location || inputBooking.meetingUrl;
|
||||
this.isBookingLocationWithEventTypeLocations(inputLocation, eventType);
|
||||
const location = inputLocation ? this.transformLocation(inputLocation) : undefined;
|
||||
|
||||
return {
|
||||
start: startTime.toISO(),
|
||||
end: endTime.toISO(),
|
||||
@@ -159,6 +168,7 @@ export class InputBookingsService_2024_08_13 {
|
||||
email: attendeeEmail ?? "",
|
||||
attendeePhoneNumber: inputBooking.attendee.phoneNumber,
|
||||
guests,
|
||||
location,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -196,17 +206,14 @@ export class InputBookingsService_2024_08_13 {
|
||||
const newRequest = { ...request };
|
||||
const userId = (await this.createBookingRequestOwnerId(request)) ?? undefined;
|
||||
|
||||
const location = request.body.location || request.body.meetingUrl;
|
||||
|
||||
if (oAuthClientParams) {
|
||||
Object.assign(newRequest, {
|
||||
userId,
|
||||
...oAuthClientParams,
|
||||
platformBookingLocation: location,
|
||||
noEmail: !oAuthClientParams.arePlatformEmailsEnabled,
|
||||
});
|
||||
} else {
|
||||
Object.assign(newRequest, { userId, platformBookingLocation: location });
|
||||
Object.assign(newRequest, { userId });
|
||||
}
|
||||
|
||||
newRequest.body = bodyTransformed.map((event) => ({
|
||||
@@ -217,6 +224,144 @@ export class InputBookingsService_2024_08_13 {
|
||||
return newRequest as unknown as BookingRequest;
|
||||
}
|
||||
|
||||
transformLocation(location: string | BookingInputLocation_2024_08_13): {
|
||||
value: string;
|
||||
optionValue: string;
|
||||
} {
|
||||
if (typeof location === "string") {
|
||||
// note(Lauris): this is for backwards compatibility because before switching to booking location objects
|
||||
// we only received a string. If someone is complaining that their location is not displaying as a URL
|
||||
// or whatever check that they are not providing a string for bookign location but one of the input objects.
|
||||
if (isURL(location, { require_protocol: false }) || location.startsWith("www.")) {
|
||||
return {
|
||||
value: "link",
|
||||
optionValue: location,
|
||||
};
|
||||
}
|
||||
|
||||
if (isPhoneNumber(location)) {
|
||||
return {
|
||||
value: "phone",
|
||||
optionValue: location,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
value: "somewhereElse",
|
||||
optionValue: location,
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "integration") {
|
||||
const integration = apiToInternalintegrationsMapping[location.integration];
|
||||
if (!integration) {
|
||||
throw new BadRequestException(`Invalid integration: ${location.integration}`);
|
||||
}
|
||||
return {
|
||||
value: integration,
|
||||
optionValue: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "address") {
|
||||
return {
|
||||
value: "inPerson",
|
||||
optionValue: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "attendeeAddress") {
|
||||
return {
|
||||
value: "attendeeInPerson",
|
||||
optionValue: location.address,
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "link") {
|
||||
return {
|
||||
value: "link",
|
||||
optionValue: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "phone") {
|
||||
return {
|
||||
value: "userPhone",
|
||||
optionValue: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "organizersDefaultApp") {
|
||||
return {
|
||||
value: "conferencing",
|
||||
optionValue: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "attendeePhone") {
|
||||
return {
|
||||
value: "phone",
|
||||
optionValue: location.phone,
|
||||
};
|
||||
}
|
||||
|
||||
if (location.type === "attendeeDefined") {
|
||||
return {
|
||||
value: "somewhereElse",
|
||||
optionValue: location.location,
|
||||
};
|
||||
}
|
||||
|
||||
throw new BadRequestException(
|
||||
`Booking location with type ${(location as BookingInputLocation_2024_08_13).type} not valid.`
|
||||
);
|
||||
}
|
||||
|
||||
private isBookingLocationWithEventTypeLocations(
|
||||
inputBookingLocation: undefined | string | BookingInputLocation_2024_08_13,
|
||||
dbEventType: EventType
|
||||
) {
|
||||
if (!inputBookingLocation || typeof inputBookingLocation === "string") {
|
||||
// note(Lauris): for backwards compatibility because we had string locations before so let them pass.
|
||||
return true;
|
||||
}
|
||||
|
||||
const eventTypeLocations = this.outputEventTypesService.transformLocations(dbEventType.locations);
|
||||
const allowedLocationTypes = eventTypeLocations.map((location) => location.type);
|
||||
|
||||
const isAllowed = allowedLocationTypes.includes(inputBookingLocation.type);
|
||||
if (!isAllowed) {
|
||||
throw new BadRequestException(
|
||||
`Booking location with type ${inputBookingLocation.type} not valid for event type with id=${
|
||||
dbEventType.id
|
||||
}. The event type has following location types: ${allowedLocationTypes.join(
|
||||
", "
|
||||
)}, and only these types are allowed for booking location.`
|
||||
);
|
||||
}
|
||||
|
||||
if (inputBookingLocation.type === "integration" && "integration" in inputBookingLocation) {
|
||||
const allowedIntegrations = eventTypeLocations
|
||||
.filter((location) => location.type === "integration")
|
||||
.map((location) => location.integration);
|
||||
|
||||
const isAllowedIntegration = allowedIntegrations.includes(inputBookingLocation.integration);
|
||||
if (!isAllowedIntegration) {
|
||||
throw new BadRequestException(
|
||||
`Booking location with integration ${
|
||||
inputBookingLocation.integration
|
||||
} not valid for event type with id=${
|
||||
dbEventType.id
|
||||
}. The event type has following integrations: ${allowedIntegrations.join(
|
||||
", "
|
||||
)}, and only these integrations are allowed for booking location.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async transformInputCreateRecurringBooking(
|
||||
inputBooking: CreateRecurringBookingInput_2024_08_13,
|
||||
platformClientId?: string
|
||||
@@ -262,6 +407,10 @@ export class InputBookingsService_2024_08_13 {
|
||||
)
|
||||
: inputBooking.attendee.email;
|
||||
|
||||
const inputLocation = inputBooking.location || inputBooking.meetingUrl;
|
||||
this.isBookingLocationWithEventTypeLocations(inputLocation, eventType);
|
||||
const location = inputLocation ? this.transformLocation(inputLocation) : undefined;
|
||||
|
||||
for (let i = 0; i < repeatsTimes; i++) {
|
||||
const endTime = startTime.plus({ minutes: eventType.length });
|
||||
|
||||
@@ -281,6 +430,7 @@ export class InputBookingsService_2024_08_13 {
|
||||
name: inputBooking.attendee.name,
|
||||
email: attendeeEmail,
|
||||
guests,
|
||||
location,
|
||||
},
|
||||
schedulingType: eventType.schedulingType,
|
||||
});
|
||||
|
||||
@@ -16233,6 +16233,125 @@
|
||||
"data"
|
||||
]
|
||||
},
|
||||
"BookingInputAddressLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "address",
|
||||
"description": "only allowed value for type is `address` - it refers to address defined by the organizer."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"BookingInputAttendeeAddressLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "attendeeAddress",
|
||||
"description": "only allowed value for type is `attendeeAddress`"
|
||||
},
|
||||
"address": {
|
||||
"type": "string",
|
||||
"example": "123 Example St, City, Country"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"address"
|
||||
]
|
||||
},
|
||||
"BookingInputAttendeeDefinedLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "attendeeDefined",
|
||||
"description": "only allowed value for type is `attendeeDefined`"
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"example": "321 Example St, City, Country"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"location"
|
||||
]
|
||||
},
|
||||
"BookingInputAttendeePhoneLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "attendeePhone",
|
||||
"description": "only allowed value for type is `attendeePhone`"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string",
|
||||
"example": "+37120993151"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"phone"
|
||||
]
|
||||
},
|
||||
"BookingInputIntegrationLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "integration",
|
||||
"description": "only allowed value for type is `integration`"
|
||||
},
|
||||
"integration": {
|
||||
"type": "string",
|
||||
"example": "cal-video",
|
||||
"enum": [
|
||||
"cal-video",
|
||||
"google-meet"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"integration"
|
||||
]
|
||||
},
|
||||
"BookingInputLinkLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "link",
|
||||
"description": "only allowed value for type is `link` - it refers to link defined by the organizer."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"BookingInputPhoneLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "phone",
|
||||
"description": "only allowed value for type is `phone` - it refers to phone defined by the organizer."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"ValidateBookingLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
},
|
||||
"Attendee": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -16356,9 +16475,30 @@
|
||||
"deprecated": true
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "Location for this booking. Displayed in email and calendar event.",
|
||||
"example": "https://example.com/meeting"
|
||||
"description": "One of the event type locations. If instead of passing one of the location objects as required by schema you are still passing a string please use an object.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeDefinedLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeePhoneLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputIntegrationLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputLinkLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputPhoneLocation_2024_08_13"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"type": "object",
|
||||
@@ -16425,9 +16565,30 @@
|
||||
"deprecated": true
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "Location for this booking. Displayed in email and calendar event.",
|
||||
"example": "https://example.com/meeting"
|
||||
"description": "One of the event type locations. If instead of passing one of the location objects as required by schema you are still passing a string please use an object.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeDefinedLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeePhoneLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputIntegrationLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputLinkLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputPhoneLocation_2024_08_13"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"type": "object",
|
||||
@@ -16500,9 +16661,30 @@
|
||||
"deprecated": true
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "Location for this booking. Displayed in email and calendar event.",
|
||||
"example": "https://example.com/meeting"
|
||||
"description": "One of the event type locations. If instead of passing one of the location objects as required by schema you are still passing a string please use an object.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeDefinedLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeePhoneLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputIntegrationLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputLinkLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputPhoneLocation_2024_08_13"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"type": "object",
|
||||
|
||||
@@ -16233,6 +16233,104 @@
|
||||
"data"
|
||||
]
|
||||
},
|
||||
"BookingInputAddressLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "address",
|
||||
"description": "only allowed value for type is `address` - it refers to address defined by the organizer."
|
||||
}
|
||||
},
|
||||
"required": ["type"]
|
||||
},
|
||||
"BookingInputAttendeeAddressLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "attendeeAddress",
|
||||
"description": "only allowed value for type is `attendeeAddress`"
|
||||
},
|
||||
"address": {
|
||||
"type": "string",
|
||||
"example": "123 Example St, City, Country"
|
||||
}
|
||||
},
|
||||
"required": ["type", "address"]
|
||||
},
|
||||
"BookingInputAttendeeDefinedLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "attendeeDefined",
|
||||
"description": "only allowed value for type is `attendeeDefined`"
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"example": "321 Example St, City, Country"
|
||||
}
|
||||
},
|
||||
"required": ["type", "location"]
|
||||
},
|
||||
"BookingInputAttendeePhoneLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "attendeePhone",
|
||||
"description": "only allowed value for type is `attendeePhone`"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string",
|
||||
"example": "+37120993151"
|
||||
}
|
||||
},
|
||||
"required": ["type", "phone"]
|
||||
},
|
||||
"BookingInputIntegrationLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "integration",
|
||||
"description": "only allowed value for type is `integration`"
|
||||
},
|
||||
"integration": {
|
||||
"type": "string",
|
||||
"example": "cal-video",
|
||||
"enum": ["cal-video", "google-meet"]
|
||||
}
|
||||
},
|
||||
"required": ["type", "integration"]
|
||||
},
|
||||
"BookingInputLinkLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "link",
|
||||
"description": "only allowed value for type is `link` - it refers to link defined by the organizer."
|
||||
}
|
||||
},
|
||||
"required": ["type"]
|
||||
},
|
||||
"BookingInputPhoneLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"example": "phone",
|
||||
"description": "only allowed value for type is `phone` - it refers to phone defined by the organizer."
|
||||
}
|
||||
},
|
||||
"required": ["type"]
|
||||
},
|
||||
"ValidateBookingLocation_2024_08_13": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
},
|
||||
"Attendee": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -16356,9 +16454,30 @@
|
||||
"deprecated": true
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "Location for this booking. Displayed in email and calendar event.",
|
||||
"example": "https://example.com/meeting"
|
||||
"description": "One of the event type locations. If instead of passing one of the location objects as required by schema you are still passing a string please use an object.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeDefinedLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeePhoneLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputIntegrationLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputLinkLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputPhoneLocation_2024_08_13"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"type": "object",
|
||||
@@ -16425,9 +16544,30 @@
|
||||
"deprecated": true
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "Location for this booking. Displayed in email and calendar event.",
|
||||
"example": "https://example.com/meeting"
|
||||
"description": "One of the event type locations. If instead of passing one of the location objects as required by schema you are still passing a string please use an object.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeDefinedLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeePhoneLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputIntegrationLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputLinkLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputPhoneLocation_2024_08_13"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"type": "object",
|
||||
@@ -16500,9 +16640,30 @@
|
||||
"deprecated": true
|
||||
},
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "Location for this booking. Displayed in email and calendar event.",
|
||||
"example": "https://example.com/meeting"
|
||||
"description": "One of the event type locations. If instead of passing one of the location objects as required by schema you are still passing a string please use an object.",
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeAddressLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeeDefinedLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputAttendeePhoneLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputIntegrationLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputLinkLocation_2024_08_13"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/BookingInputPhoneLocation_2024_08_13"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"type": "object",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { InputLocation_2024_06_14, InputTeamLocation_2024_06_14 } from "@calcom/platform-types";
|
||||
import { type Integration_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
import type {
|
||||
AttendeeAddressLocation,
|
||||
@@ -12,15 +11,39 @@ import type {
|
||||
OrganizerConferencingSchema,
|
||||
} from "../internal/locations";
|
||||
|
||||
const apiToInternalintegrationsMapping: Record<
|
||||
Integration_2024_06_14,
|
||||
"integrations:daily" | "integrations:google:meet" | "integrations:office365_video" | "integrations:zoom"
|
||||
> = {
|
||||
export const apiToInternalintegrationsMapping = {
|
||||
"cal-video": "integrations:daily",
|
||||
"google-meet": "integrations:google:meet",
|
||||
"office365-video": "integrations:office365_video",
|
||||
zoom: "integrations:zoom",
|
||||
};
|
||||
"whereby-video": "integrations:whereby_video",
|
||||
"whatsapp-video": "integrations:whatsapp_video",
|
||||
"webex-video": "integrations:webex_video",
|
||||
"telegram-video": "integrations:telegram_video",
|
||||
tandem: "integrations:tandem",
|
||||
"sylaps-video": "integrations:sylaps_video",
|
||||
"skype-video": "integrations:skype_video",
|
||||
"sirius-video": "integrations:sirius_video_video",
|
||||
"signal-video": "integrations:signal_video",
|
||||
"shimmer-video": "integrations:shimmer_video",
|
||||
"salesroom-video": "integrations:salesroom_video",
|
||||
"roam-video": "integrations:roam_video",
|
||||
"riverside-video": "integrations:riverside_video",
|
||||
"ping-video": "integrations:ping_video",
|
||||
"mirotalk-video": "integrations:mirotalk_video",
|
||||
jitsi: "integrations:jitsi",
|
||||
"jelly-video": "integrations:jelly_video",
|
||||
"jelly-conferencing": "integrations:jelly_conferencing",
|
||||
huddle: "integrations:huddle01",
|
||||
"facetime-video": "integrations:facetime_video",
|
||||
"element-call-video": "integrations:element-call_video",
|
||||
"eightxeight-video": "integrations:eightxeight_video",
|
||||
"discord-video": "integrations:discord_video",
|
||||
"demodesk-video": "integrations:demodesk_video",
|
||||
"campsite-conferencing": "integrations:campsite_conferencing",
|
||||
"campfire-video": "integrations:campfire_video",
|
||||
"around-video": "integrations:around_video",
|
||||
} as const;
|
||||
|
||||
function transformLocation<T extends InputLocation_2024_06_14>(location: T) {
|
||||
const { type } = location;
|
||||
|
||||
@@ -43,6 +43,7 @@ export {
|
||||
systemAfterFieldTitle,
|
||||
systemAfterFieldNotes,
|
||||
systemAfterFieldGuests,
|
||||
apiToInternalintegrationsMapping,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
export type {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { ApiExtraModels, ApiProperty, ApiPropertyOptional, getSchemaPath } from "@nestjs/swagger";
|
||||
import { Type } from "class-transformer";
|
||||
import type { ValidationArguments, ValidationOptions } from "class-validator";
|
||||
import {
|
||||
@@ -22,6 +22,17 @@ import { isValidPhoneNumber } from "libphonenumber-js";
|
||||
|
||||
import type { BookingLanguageType } from "./language";
|
||||
import { BookingLanguage } from "./language";
|
||||
import type { BookingInputLocation_2024_08_13 } from "./location.input";
|
||||
import {
|
||||
BookingInputAddressLocation_2024_08_13,
|
||||
BookingInputAttendeeAddressLocation_2024_08_13,
|
||||
BookingInputAttendeeDefinedLocation_2024_08_13,
|
||||
BookingInputAttendeePhoneLocation_2024_08_13,
|
||||
BookingInputIntegrationLocation_2024_08_13,
|
||||
BookingInputLinkLocation_2024_08_13,
|
||||
BookingInputPhoneLocation_2024_08_13,
|
||||
ValidateBookingLocation_2024_08_13,
|
||||
} from "./location.input";
|
||||
import { ValidateMetadata } from "./validators/validate-metadata";
|
||||
|
||||
function RequireEmailOrPhone(validationOptions?: ValidationOptions) {
|
||||
@@ -98,6 +109,16 @@ class Attendee {
|
||||
language?: BookingLanguageType;
|
||||
}
|
||||
|
||||
@ApiExtraModels(
|
||||
BookingInputAddressLocation_2024_08_13,
|
||||
BookingInputAttendeeAddressLocation_2024_08_13,
|
||||
BookingInputAttendeeDefinedLocation_2024_08_13,
|
||||
BookingInputAttendeePhoneLocation_2024_08_13,
|
||||
BookingInputIntegrationLocation_2024_08_13,
|
||||
BookingInputLinkLocation_2024_08_13,
|
||||
BookingInputPhoneLocation_2024_08_13,
|
||||
ValidateBookingLocation_2024_08_13
|
||||
)
|
||||
export class CreateBookingInput_2024_08_13 {
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
@@ -155,14 +176,24 @@ export class CreateBookingInput_2024_08_13 {
|
||||
@IsOptional()
|
||||
meetingUrl?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
type: String,
|
||||
description: "Location for this booking. Displayed in email and calendar event.",
|
||||
example: "https://example.com/meeting",
|
||||
required: false,
|
||||
})
|
||||
@IsOptional()
|
||||
location?: string;
|
||||
@ValidateBookingLocation_2024_08_13()
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
"One of the event type locations. If instead of passing one of the location objects as required by schema you are still passing a string please use an object.",
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(BookingInputAddressLocation_2024_08_13) },
|
||||
{ $ref: getSchemaPath(BookingInputAttendeeAddressLocation_2024_08_13) },
|
||||
{ $ref: getSchemaPath(BookingInputAttendeeDefinedLocation_2024_08_13) },
|
||||
{ $ref: getSchemaPath(BookingInputAttendeePhoneLocation_2024_08_13) },
|
||||
{ $ref: getSchemaPath(BookingInputIntegrationLocation_2024_08_13) },
|
||||
{ $ref: getSchemaPath(BookingInputLinkLocation_2024_08_13) },
|
||||
{ $ref: getSchemaPath(BookingInputPhoneLocation_2024_08_13) },
|
||||
],
|
||||
})
|
||||
@Type(() => Object)
|
||||
// note(Lauris): string is for backwards compatability
|
||||
location?: BookingInputLocation_2024_08_13 | string;
|
||||
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
import { ApiProperty as DocsProperty } from "@nestjs/swagger";
|
||||
import { plainToInstance } from "class-transformer";
|
||||
import { IsString, IsIn, IsPhoneNumber } from "class-validator";
|
||||
import type { ValidationOptions, ValidatorConstraintInterface } from "class-validator";
|
||||
import { registerDecorator, validate, ValidatorConstraint } from "class-validator";
|
||||
|
||||
export const inputLocations = [
|
||||
"address",
|
||||
"link",
|
||||
"integration",
|
||||
"phone",
|
||||
"attendeeAddress",
|
||||
"attendeePhone",
|
||||
"attendeeDefined",
|
||||
"organizersDefaultApp",
|
||||
] as const;
|
||||
|
||||
export class BookingInputAddressLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "address",
|
||||
description: "only allowed value for type is `address` - it refers to address defined by the organizer.",
|
||||
})
|
||||
type!: "address";
|
||||
}
|
||||
|
||||
export class BookingInputLinkLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "link",
|
||||
description: "only allowed value for type is `link` - it refers to link defined by the organizer.",
|
||||
})
|
||||
type!: "link";
|
||||
}
|
||||
|
||||
export const supportedIntegrations = [
|
||||
"cal-video",
|
||||
"google-meet",
|
||||
"zoom",
|
||||
"whereby-video",
|
||||
"whatsapp-video",
|
||||
"webex-video",
|
||||
"telegram-video",
|
||||
"tandem",
|
||||
"sylaps-video",
|
||||
"skype-video",
|
||||
"sirius-video",
|
||||
"signal-video",
|
||||
"shimmer-video",
|
||||
"salesroom-video",
|
||||
"roam-video",
|
||||
"riverside-video",
|
||||
"ping-video",
|
||||
"office365-video",
|
||||
"mirotalk-video",
|
||||
"jitsi",
|
||||
"jelly-video",
|
||||
"jelly-conferencing",
|
||||
"huddle",
|
||||
"facetime-video",
|
||||
"element-call-video",
|
||||
"eightxeight-video",
|
||||
"discord-video",
|
||||
"demodesk-video",
|
||||
"campsite-conferencing",
|
||||
"campfire-video",
|
||||
"around-video",
|
||||
] as const;
|
||||
export type Integration_2024_08_13 = (typeof supportedIntegrations)[number];
|
||||
|
||||
export class BookingInputIntegrationLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({ example: "integration", description: "only allowed value for type is `integration`" })
|
||||
type!: "integration";
|
||||
|
||||
@IsIn(supportedIntegrations)
|
||||
@DocsProperty({ example: supportedIntegrations[0], enum: supportedIntegrations })
|
||||
integration!: Integration_2024_08_13;
|
||||
}
|
||||
|
||||
export class BookingInputPhoneLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "phone",
|
||||
description: "only allowed value for type is `phone` - it refers to phone defined by the organizer.",
|
||||
})
|
||||
type!: "phone";
|
||||
}
|
||||
|
||||
export class BookingInputOrganizersDefaultAppLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "organizersDefaultApp",
|
||||
description:
|
||||
"only allowed value for type is `organizersDefaultApp` - it refers to the default app defined by the organizer.",
|
||||
})
|
||||
type!: "organizersDefaultApp";
|
||||
}
|
||||
|
||||
export class BookingInputAttendeeAddressLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "attendeeAddress",
|
||||
description: "only allowed value for type is `attendeeAddress`",
|
||||
})
|
||||
type!: "attendeeAddress";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "123 Example St, City, Country" })
|
||||
address!: string;
|
||||
}
|
||||
export class BookingInputAttendeePhoneLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({ example: "attendeePhone", description: "only allowed value for type is `attendeePhone`" })
|
||||
type!: "attendeePhone";
|
||||
|
||||
@IsPhoneNumber()
|
||||
@DocsProperty({ example: "+37120993151" })
|
||||
phone!: string;
|
||||
}
|
||||
|
||||
export class BookingInputAttendeeDefinedLocation_2024_08_13 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "attendeeDefined",
|
||||
description: "only allowed value for type is `attendeeDefined`",
|
||||
})
|
||||
type!: "attendeeDefined";
|
||||
|
||||
@IsString()
|
||||
@DocsProperty({ example: "321 Example St, City, Country" })
|
||||
location!: string;
|
||||
}
|
||||
|
||||
export type BookingInputLocation_2024_08_13 =
|
||||
| BookingInputAddressLocation_2024_08_13
|
||||
| BookingInputLinkLocation_2024_08_13
|
||||
| BookingInputIntegrationLocation_2024_08_13
|
||||
| BookingInputPhoneLocation_2024_08_13
|
||||
| BookingInputAttendeeAddressLocation_2024_08_13
|
||||
| BookingInputAttendeePhoneLocation_2024_08_13
|
||||
| BookingInputAttendeeDefinedLocation_2024_08_13
|
||||
| BookingInputOrganizersDefaultAppLocation_2024_08_13;
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class BookingInputLocationValidator_2024_08_13 implements ValidatorConstraintInterface {
|
||||
private validationMessage = "";
|
||||
|
||||
private classTypeMap: { [key: string]: new () => BookingInputLocation_2024_08_13 } = {
|
||||
address: BookingInputAddressLocation_2024_08_13,
|
||||
link: BookingInputLinkLocation_2024_08_13,
|
||||
integration: BookingInputIntegrationLocation_2024_08_13,
|
||||
phone: BookingInputPhoneLocation_2024_08_13,
|
||||
attendeePhone: BookingInputAttendeePhoneLocation_2024_08_13,
|
||||
attendeeAddress: BookingInputAttendeeAddressLocation_2024_08_13,
|
||||
attendeeDefined: BookingInputAttendeeDefinedLocation_2024_08_13,
|
||||
organizersDefaultApp: BookingInputOrganizersDefaultAppLocation_2024_08_13,
|
||||
};
|
||||
|
||||
async validate(location: { type: string } | string) {
|
||||
if (typeof location === "string") {
|
||||
// note(Lauris): this is for backwards compatibility because before switching to booking location objects
|
||||
// we only received a string. If someone is complaining that their location is not displaying as a URL
|
||||
// or whatever check that they are not providing a string for bookign location but one of the input objects.
|
||||
return true;
|
||||
}
|
||||
|
||||
const { type } = location;
|
||||
if (!type) {
|
||||
this.validationMessage = `BookingInputLocationValidator_2024_08_13 - Booking 'location' must have a 'type' property.`;
|
||||
return false;
|
||||
}
|
||||
|
||||
const ClassType = this.classTypeMap[type];
|
||||
if (!ClassType) {
|
||||
this.validationMessage = `BookingInputLocationValidator_2024_08_13 - Unsupported booking location type '${type}'. Valid types are address, link, integration, phone, attendeePhone, attendeeAddress, attendeeDefined and organizersDefaultApp.`;
|
||||
return false;
|
||||
}
|
||||
|
||||
const instance = plainToInstance(ClassType, location);
|
||||
const errors = await validate(instance);
|
||||
if (errors.length > 0) {
|
||||
const message = errors.flatMap((error) => Object.values(error.constraints || {})).join(", ");
|
||||
this.validationMessage = `BookingInputLocationValidator_2024_08_13 - Validation failed for ${type} location: ${message}`;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
defaultMessage() {
|
||||
return (
|
||||
this.validationMessage ||
|
||||
`BookingInputLocationValidator_2024_08_13 - Validation failed for one or more location entries.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function ValidateBookingLocation_2024_08_13(validationOptions?: ValidationOptions) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return function (object: any, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: "ValidateLocation",
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: new BookingInputLocationValidator_2024_08_13(),
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user