Skip to content

Commit 34d4f39

Browse files
authored
fix: v2 event type disable guests (calcom#21753)
* fix: v2 event type disable guests * fix: implement cubic feedback
1 parent a4ef8d4 commit 34d4f39

2 files changed

Lines changed: 132 additions & 2 deletions

File tree

apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
ApiSuccessResponse,
3535
CreateEventTypeInput_2024_06_14,
3636
EventTypeOutput_2024_06_14,
37+
GuestsDefaultFieldOutput_2024_06_14,
3738
NameDefaultFieldInput_2024_06_14,
3839
NotesDefaultFieldInput_2024_06_14,
3940
UpdateEventTypeInput_2024_06_14,
@@ -535,6 +536,7 @@ describe("Event types Endpoints", () => {
535536
body.lockTimeZoneToggleOnBookingPage
536537
);
537538
expect(createdEventType.color).toEqual(body.color);
539+
expect(createdEventType.disableGuests).toEqual(false);
538540

539541
const expectedBookingFields = [
540542
{ ...defaultResponseBookingFieldName, ...nameBookingField },
@@ -1041,6 +1043,7 @@ describe("Event types Endpoints", () => {
10411043
expect(updatedEventType.description).toEqual(eventType.description);
10421044
expect(updatedEventType.lengthInMinutes).toEqual(eventType.lengthInMinutes);
10431045
expect(updatedEventType.locations).toEqual(eventType.locations);
1046+
expect(updatedEventType.disableGuests).toEqual(false);
10441047

10451048
const expectedBookingFields = [
10461049
{ ...defaultResponseBookingFieldName, ...nameBookingField },
@@ -1887,6 +1890,96 @@ describe("Event types Endpoints", () => {
18871890
});
18881891
});
18891892

1893+
describe("toggle disable guests", () => {
1894+
let eventTypeWithGuestsDisabledId: number;
1895+
1896+
it("should create an event type with guests disabled", async () => {
1897+
const body: CreateEventTypeInput_2024_06_14 = {
1898+
title: "Coding class guests disabled",
1899+
slug: "coding-class-guests-disabled",
1900+
description: "Let's learn how to code like a pro.",
1901+
lengthInMinutes: 60,
1902+
disableGuests: true,
1903+
};
1904+
1905+
return request(app.getHttpServer())
1906+
.post("/api/v2/event-types")
1907+
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
1908+
.send(body)
1909+
.expect(201)
1910+
.then(async (response) => {
1911+
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
1912+
const createdEventType = responseBody.data;
1913+
expect(createdEventType).toHaveProperty("id");
1914+
expect(createdEventType.title).toEqual(body.title);
1915+
expect(createdEventType.description).toEqual(body.description);
1916+
expect(createdEventType.lengthInMinutes).toEqual(body.lengthInMinutes);
1917+
1918+
expect(createdEventType.disableGuests).toEqual(true);
1919+
const guestsBookingField = createdEventType.bookingFields.find(
1920+
(field) => field.slug === "guests"
1921+
) as GuestsDefaultFieldOutput_2024_06_14 | undefined;
1922+
expect(guestsBookingField?.hidden).toEqual(true);
1923+
1924+
eventTypeWithGuestsDisabledId = createdEventType.id;
1925+
});
1926+
});
1927+
1928+
it("should update an event type with guests enabled", async () => {
1929+
const body: UpdateEventTypeInput_2024_06_14 = {
1930+
disableGuests: false,
1931+
};
1932+
1933+
return request(app.getHttpServer())
1934+
.patch(`/api/v2/event-types/${eventTypeWithGuestsDisabledId}`)
1935+
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
1936+
.send(body)
1937+
.expect(200)
1938+
.then(async (response) => {
1939+
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
1940+
const updatedEventType = responseBody.data;
1941+
1942+
expect(updatedEventType.disableGuests).toEqual(false);
1943+
const guestsBookingField = updatedEventType.bookingFields.find(
1944+
(field) => field.slug === "guests"
1945+
) as GuestsDefaultFieldOutput_2024_06_14 | undefined;
1946+
expect(guestsBookingField?.hidden).toEqual(false);
1947+
1948+
eventTypeWithGuestsDisabledId = updatedEventType.id;
1949+
});
1950+
});
1951+
1952+
it("should update an event type with guests disabled", async () => {
1953+
const body: UpdateEventTypeInput_2024_06_14 = {
1954+
disableGuests: true,
1955+
};
1956+
1957+
return request(app.getHttpServer())
1958+
.patch(`/api/v2/event-types/${eventTypeWithGuestsDisabledId}`)
1959+
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
1960+
.send(body)
1961+
.expect(200)
1962+
.then(async (response) => {
1963+
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
1964+
const updatedEventType = responseBody.data;
1965+
1966+
expect(updatedEventType.disableGuests).toEqual(true);
1967+
const guestsBookingField = updatedEventType.bookingFields.find(
1968+
(field) => field.slug === "guests"
1969+
) as GuestsDefaultFieldOutput_2024_06_14 | undefined;
1970+
expect(guestsBookingField?.hidden).toEqual(true);
1971+
1972+
eventTypeWithGuestsDisabledId = updatedEventType.id;
1973+
});
1974+
});
1975+
1976+
afterAll(async () => {
1977+
if (eventTypeWithGuestsDisabledId) {
1978+
await eventTypesRepositoryFixture.delete(eventTypeWithGuestsDisabledId);
1979+
}
1980+
});
1981+
});
1982+
18901983
afterAll(async () => {
18911984
await oauthClientRepositoryFixture.delete(oAuthClient.id);
18921985
await teamRepositoryFixture.delete(organization.id);

apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/input-event-types.service.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { validateCustomEventName, EventTypeMetaDataSchema } from "@calcom/platfo
3232
import {
3333
CreateEventTypeInput_2024_06_14,
3434
DestinationCalendar_2024_06_14,
35+
InputBookingField_2024_06_14,
3536
OutputUnknownLocation_2024_06_14,
3637
UpdateEventTypeInput_2024_06_14,
3738
} from "@calcom/platform-types";
@@ -117,16 +118,23 @@ export class InputEventTypesService_2024_06_14 {
117118
seats,
118119
customName,
119120
useDestinationCalendarEmail,
121+
disableGuests,
120122
...rest
121123
} = inputEventType;
122124
const confirmationPolicyTransformed = this.transformInputConfirmationPolicy(confirmationPolicy);
123125

124126
const locationsTransformed = locations?.length ? this.transformInputLocations(locations) : undefined;
127+
128+
const effectiveBookingFields =
129+
disableGuests !== undefined
130+
? this.getBookingFieldsWithGuestsToggled(bookingFields, disableGuests)
131+
: bookingFields;
132+
125133
const eventType = {
126134
...rest,
127135
length: lengthInMinutes,
128136
locations: locationsTransformed,
129-
bookingFields: this.transformInputBookingFields(bookingFields),
137+
bookingFields: this.transformInputBookingFields(effectiveBookingFields),
130138
bookingLimits: bookingLimitsCount ? this.transformInputIntervalLimits(bookingLimitsCount) : undefined,
131139
durationLimits: bookingLimitsDuration
132140
? this.transformInputIntervalLimits(bookingLimitsDuration)
@@ -167,6 +175,7 @@ export class InputEventTypesService_2024_06_14 {
167175
seats,
168176
customName,
169177
useDestinationCalendarEmail,
178+
disableGuests,
170179
...rest
171180
} = inputEventType;
172181
const eventTypeDb = await this.eventTypesRepository.getEventTypeWithMetaData(eventTypeId);
@@ -176,11 +185,18 @@ export class InputEventTypesService_2024_06_14 {
176185

177186
const confirmationPolicyTransformed = this.transformInputConfirmationPolicy(confirmationPolicy);
178187

188+
const effectiveBookingFields =
189+
disableGuests !== undefined
190+
? this.getBookingFieldsWithGuestsToggled(bookingFields, disableGuests)
191+
: bookingFields;
192+
179193
const eventType = {
180194
...rest,
181195
length: lengthInMinutes,
182196
locations: locations ? this.transformInputLocations(locations) : undefined,
183-
bookingFields: bookingFields ? this.transformInputBookingFields(bookingFields) : undefined,
197+
bookingFields: effectiveBookingFields
198+
? this.transformInputBookingFields(effectiveBookingFields)
199+
: undefined,
184200
bookingLimits: bookingLimitsCount ? this.transformInputIntervalLimits(bookingLimitsCount) : undefined,
185201
durationLimits: bookingLimitsDuration
186202
? this.transformInputIntervalLimits(bookingLimitsDuration)
@@ -206,6 +222,27 @@ export class InputEventTypesService_2024_06_14 {
206222
return eventType;
207223
}
208224

225+
getBookingFieldsWithGuestsToggled(
226+
bookingFields: InputBookingField_2024_06_14[] | undefined,
227+
hideGuests: boolean
228+
) {
229+
const toggledGuestsBookingField: InputBookingField_2024_06_14 = { slug: "guests", hidden: hideGuests };
230+
if (!bookingFields) {
231+
return [toggledGuestsBookingField];
232+
}
233+
234+
const bookingFieldsCopy = [...bookingFields];
235+
236+
const guestsBookingField = bookingFieldsCopy.find((field) => "slug" in field && field.slug === "guests");
237+
if (guestsBookingField) {
238+
Object.assign(guestsBookingField, { hidden: hideGuests });
239+
return bookingFieldsCopy;
240+
}
241+
242+
bookingFieldsCopy.push(toggledGuestsBookingField);
243+
return bookingFieldsCopy;
244+
}
245+
209246
transformInputLocations(inputLocations: CreateEventTypeInput_2024_06_14["locations"]) {
210247
return transformLocationsApiToInternal(inputLocations);
211248
}

0 commit comments

Comments
 (0)