Skip to content

Scheduling infrastructure for absolutely everyone.

feat: v2 API enable updating event-type bookingFields (#15172)

Lauris Skraucis01933e5c15ec
diff --git a/apps/api/v2/src/ee/event-types/controllers/event-types.controller.e2e-spec.ts b/apps/api/v2/src/ee/event-types/controllers/event-types.controller.e2e-spec.ts
index f5f4eb58d37..c561bcd2f15 100644
--- a/apps/api/v2/src/ee/event-types/controllers/event-types.controller.e2e-spec.ts
+++ b/apps/api/v2/src/ee/event-types/controllers/event-types.controller.e2e-spec.ts
@@ -2,6 +2,8 @@ import { bootstrap } from "@/app";
import { AppModule } from "@/app.module";
import { EventTypesModule } from "@/ee/event-types/event-types.module";
import { CreateEventTypeInput } from "@/ee/event-types/inputs/create-event-type.input";
+import { Editable } from "@/ee/event-types/inputs/enums/editable";
+import { BaseField } from "@/ee/event-types/inputs/enums/field-type";
import { UpdateEventTypeInput } from "@/ee/event-types/inputs/update-event-type.input";
import { GetEventTypePublicOutput } from "@/ee/event-types/outputs/get-event-type-public.output";
import { GetEventTypeOutput } from "@/ee/event-types/outputs/get-event-type.output";
@@ -23,7 +25,12 @@ import { UserRepositoryFixture } from "test/fixtures/repository/users.repository
import { withAccessTokenAuth } from "test/utils/withAccessTokenAuth";
import { SUCCESS_STATUS } from "@calcom/platform-constants";
-import { EventTypesByViewer, EventTypesPublic } from "@calcom/platform-libraries";
+import {
+ EventTypesByViewer,
+ EventTypesPublic,
+ eventTypeBookingFields,
+ eventTypeLocations,
+} from "@calcom/platform-libraries";
import { ApiSuccessResponse } from "@calcom/platform-types";
describe("Event types Endpoints", () => {
@@ -197,6 +204,77 @@ describe("Event types Endpoints", () => {
});
});
+ it("should update event type locations", async () => {
+ const locations = [{ type: "inPerson", address: "123 Main St" }];
+
+ const body: UpdateEventTypeInput = {
+ locations,
+ };
+
+ return request(app.getHttpServer())
+ .patch(`/api/v2/event-types/${eventType.id}`)
+ .send(body)
+ .expect(200)
+ .then(async (response) => {
+ const responseBody: ApiSuccessResponse<EventType> = response.body;
+ const responseLocations = eventTypeLocations.parse(responseBody.data.locations);
+ expect(responseLocations).toBeDefined();
+ expect(responseLocations.length).toEqual(locations.length);
+ expect(responseLocations).toEqual(locations);
+ eventType.locations = responseLocations;
+ });
+ });
+
+ it("should update event type bookingFields", async () => {
+ const bookingFieldName = "location-name";
+ const bookingFields = [
+ {
+ name: bookingFieldName,
+ type: BaseField.radio,
+ label: "Location",
+ options: [
+ {
+ label: "Via Bari 10, Roma, 90119, Italy",
+ value: "Via Bari 10, Roma, 90119, Italy",
+ },
+ {
+ label: "Via Reale 28, Roma, 9001, Italy",
+ value: "Via Reale 28, Roma, 9001, Italy",
+ },
+ ],
+ sources: [
+ {
+ id: "user",
+ type: "user",
+ label: "User",
+ fieldRequired: true,
+ },
+ ],
+ editable: Editable.user,
+ required: true,
+ placeholder: "",
+ },
+ ];
+
+ const body: UpdateEventTypeInput = {
+ bookingFields,
+ };
+
+ return request(app.getHttpServer())
+ .patch(`/api/v2/event-types/${eventType.id}`)
+ .send(body)
+ .expect(200)
+ .then(async (response) => {
+ const responseBody: ApiSuccessResponse<EventType> = response.body;
+ const responseBookingFields = eventTypeBookingFields.parse(responseBody.data.bookingFields);
+ expect(responseBookingFields).toBeDefined();
+ // note(Lauris): response bookingFields are already existing default bookingFields + the new one
+ const responseBookingField = responseBookingFields.find((field) => field.name === bookingFieldName);
+ expect(responseBookingField).toEqual(bookingFields[0]);
+ eventType.bookingFields = responseBookingFields;
+ });
+ });
+
it(`/GET/:id`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types/${eventType.id}`)
diff --git a/apps/api/v2/src/ee/event-types/inputs/update-event-type.input.ts b/apps/api/v2/src/ee/event-types/inputs/update-event-type.input.ts
index 8b3d9017073..8c112db433e 100644
--- a/apps/api/v2/src/ee/event-types/inputs/update-event-type.input.ts
+++ b/apps/api/v2/src/ee/event-types/inputs/update-event-type.input.ts
@@ -275,11 +275,11 @@ export class UpdateEventTypeInput {
// @IsOptional()
// parentId?: number;
- // @IsOptional()
- // @IsArray()
- // @ValidateNested({ each: true })
- // @Type(() => BookingField)
- // bookingFields?: BookingField[];
+ @IsOptional()
+ @IsArray()
+ @ValidateNested({ each: true })
+ @Type(() => BookingField)
+ bookingFields?: BookingField[];
// @IsString()
// @IsOptional()
diff --git a/packages/platform/libraries/index.ts b/packages/platform/libraries/index.ts
index a2e91c469e0..e4790782d02 100644
--- a/packages/platform/libraries/index.ts
+++ b/packages/platform/libraries/index.ts
@@ -77,3 +77,5 @@ export { createNewUsersConnectToOrgIfExists };
export { getAllUserBookings };
export { getBookingInfo };
export { handleCancelBooking };
+
+export { eventTypeBookingFields, eventTypeLocations } from "@calcom/prisma/zod-utils";