Skip to content

Commit 758b820

Browse files
authored
fix: slugified eventype slug (calcom#25791)
1 parent b46fb82 commit 758b820

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { UserWithProfile } from "@/modules/users/users.repository";
2828
import { Injectable, BadRequestException } from "@nestjs/common";
2929

30+
import { slugify } from "@calcom/platform-libraries";
3031
import { getApps, getUsersCredentialsIncludeServiceAccountKey } from "@calcom/platform-libraries/app-store";
3132
import {
3233
validateCustomEventName,
@@ -129,6 +130,7 @@ export class InputEventTypesService_2024_06_14 {
129130
useDestinationCalendarEmail,
130131
disableGuests,
131132
bookerActiveBookingsLimit,
133+
slug,
132134
...rest
133135
} = inputEventType;
134136
const confirmationPolicyTransformed = this.transformInputConfirmationPolicy(confirmationPolicy);
@@ -144,6 +146,8 @@ export class InputEventTypesService_2024_06_14 {
144146
? this.transformInputBookerActiveBookingsLimit(bookerActiveBookingsLimit)
145147
: {};
146148

149+
const slugifiedSlug = slugify(slug);
150+
147151
const metadata: EventTypeMetadata = {
148152
bookerLayouts: this.transformInputBookerLayouts(bookerLayouts),
149153
requiresConfirmationThreshold:
@@ -153,6 +157,7 @@ export class InputEventTypesService_2024_06_14 {
153157

154158
const eventType = {
155159
...rest,
160+
slug: slugifiedSlug,
156161
length: lengthInMinutes,
157162
locations: locationsTransformed,
158163
bookingFields: this.transformInputBookingFields(effectiveBookingFields),
@@ -209,6 +214,7 @@ export class InputEventTypesService_2024_06_14 {
209214
useDestinationCalendarEmail,
210215
disableGuests,
211216
bookerActiveBookingsLimit,
217+
slug,
212218
...rest
213219
} = inputEventType;
214220
const eventTypeDb = await this.eventTypesRepository.getEventTypeWithMetaData(eventTypeId);
@@ -243,6 +249,7 @@ export class InputEventTypesService_2024_06_14 {
243249

244250
const eventType = {
245251
...rest,
252+
...(slug ? { slug: slugify(slug) } : {}),
246253
length: lengthInMinutes,
247254
locations: locations ? this.transformInputLocations(locations) : undefined,
248255
bookingFields: effectiveBookingFields

apps/api/v2/src/modules/organizations/event-types/services/input.service.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { UsersRepository } from "@/modules/users/users.repository";
88
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
99

1010
import { SchedulingType } from "@calcom/platform-libraries";
11+
import { slugify } from "@calcom/platform-libraries";
1112
import { EventTypeMetadata } from "@calcom/platform-libraries/event-types";
1213
import {
1314
CreateTeamEventTypeInput_2024_06_14,
@@ -42,11 +43,13 @@ export class InputOrganizationsEventTypesService {
4243
teamId: number,
4344
inputEventType: CreateTeamEventTypeInput_2024_06_14
4445
) {
46+
const slugifiedInputEventType = { ...inputEventType, slug: slugify(inputEventType.slug) };
47+
4548
await this.validateInputLocations(teamId, inputEventType.locations);
4649
await this.validateHosts(teamId, inputEventType.hosts);
47-
await this.validateTeamEventTypeSlug(teamId, inputEventType.slug);
50+
await this.validateTeamEventTypeSlug(teamId, slugifiedInputEventType.slug);
4851

49-
const transformedBody = await this.transformInputCreateTeamEventType(teamId, inputEventType);
52+
const transformedBody = await this.transformInputCreateTeamEventType(teamId, slugifiedInputEventType);
5053

5154
await this.inputEventTypesService.validateEventTypeInputs({
5255
seatsPerTimeSlot: transformedBody.seatsPerTimeSlot,
@@ -75,13 +78,21 @@ export class InputOrganizationsEventTypesService {
7578
teamId: number,
7679
inputEventType: UpdateTeamEventTypeInput_2024_06_14
7780
) {
81+
const slugifiedInputEventType = inputEventType.slug
82+
? { ...inputEventType, slug: slugify(inputEventType.slug) }
83+
: inputEventType;
84+
7885
await this.validateInputLocations(teamId, inputEventType.locations);
7986
await this.validateHosts(teamId, inputEventType.hosts);
80-
if (inputEventType.slug) {
81-
await this.validateTeamEventTypeSlug(teamId, inputEventType.slug);
87+
if (slugifiedInputEventType.slug) {
88+
await this.validateTeamEventTypeSlug(teamId, slugifiedInputEventType.slug);
8289
}
8390

84-
const transformedBody = await this.transformInputUpdateTeamEventType(eventTypeId, teamId, inputEventType);
91+
const transformedBody = await this.transformInputUpdateTeamEventType(
92+
eventTypeId,
93+
teamId,
94+
slugifiedInputEventType
95+
);
8596

8697
await this.inputEventTypesService.validateEventTypeInputs({
8798
eventTypeId: eventTypeId,

0 commit comments

Comments
 (0)