refactor: v2 default booking fields (#18287)
* feat: allow title,notes,reschedule reason inputs * refactor: v2 event type default booking fields as in web app * wip: input validation * input field validation * fix: tests * chore: bump libraries * remove change in docs * fix input type * chore: ensure additional notes at the end * fixup! Merge branch 'main' into lauris/cal-4932-platform-refactor-default-booking-fields --------- Co-authored-by: Morgan Vernay <[email protected]> Co-authored-by: Morgan <[email protected]>
This commit is contained in:
19 files changed
+7050
-611
No files matched your search
+8
-6
@@ -2,7 +2,7 @@ import { defaultEvents } from "@calcom/lib/defaultEvents";
|
||||
import type { SystemField } from "@calcom/lib/event-types/transformers";
|
||||
import {
|
||||
transformLocationsApiToInternal,
|
||||
transformBookingFieldsApiResponseToInternal,
|
||||
transformBookingFieldsApiToInternal,
|
||||
systemBeforeFieldName,
|
||||
systemBeforeFieldEmail,
|
||||
systemBeforeFieldLocation,
|
||||
@@ -16,10 +16,10 @@ import {
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
|
||||
import type {
|
||||
CustomFieldOutput_2024_06_14,
|
||||
EmailDefaultFieldOutput_2024_06_14,
|
||||
EventTypeOutput_2024_06_14,
|
||||
InputLocation_2024_06_14,
|
||||
KnownBookingField_2024_06_14,
|
||||
NameDefaultFieldOutput_2024_06_14,
|
||||
TeamEventTypeOutput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
@@ -329,7 +329,9 @@ function getBookingFields(
|
||||
bookingFields: EventTypeOutput_2024_06_14["bookingFields"],
|
||||
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined
|
||||
) {
|
||||
const transformedBookingFields = transformBookingFieldsApiResponseToInternal(bookingFields);
|
||||
const transformedBookingFields = transformBookingFieldsApiToInternal(
|
||||
bookingFields.filter((field) => isKnownField(field))
|
||||
);
|
||||
|
||||
const hasNameField = transformedBookingFields.some((field) => field.name === "name");
|
||||
const hasEmailField = transformedBookingFields.some((field) => field.name === "email");
|
||||
@@ -369,10 +371,10 @@ function getBookingFields(
|
||||
return eventTypeBookingFields.brand<"HAS_SYSTEM_FIELDS">().parse(fieldsWithSystem);
|
||||
}
|
||||
|
||||
function isCustomField(
|
||||
function isKnownField(
|
||||
field: EventTypeOutput_2024_06_14["bookingFields"][number]
|
||||
): field is CustomFieldOutput_2024_06_14 {
|
||||
return field.type !== "unknown" && !field.isDefault;
|
||||
): field is KnownBookingField_2024_06_14 {
|
||||
return field.type !== "unknown";
|
||||
}
|
||||
|
||||
function getBookingWindow(inputBookingWindow: EventTypeOutput_2024_06_14["bookingWindow"]) {
|
||||
|
||||
@@ -126,7 +126,7 @@ export { EventTypeMetaDataSchema, userMetadata, bookingMetadataSchema } from "@c
|
||||
|
||||
export {
|
||||
// note(Lauris): Api to internal
|
||||
transformBookingFieldsApiRequestToInternal,
|
||||
transformBookingFieldsApiToInternal,
|
||||
transformLocationsApiToInternal,
|
||||
transformIntervalLimitsApiToInternal,
|
||||
transformFutureBookingLimitsApiToInternal,
|
||||
@@ -155,6 +155,9 @@ export {
|
||||
systemBeforeFieldEmail,
|
||||
systemBeforeFieldLocation,
|
||||
systemAfterFieldRescheduleReason,
|
||||
systemAfterFieldTitle,
|
||||
systemAfterFieldNotes,
|
||||
systemAfterFieldGuests,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
export type {
|
||||
|
||||
+256
-26
@@ -21,9 +21,14 @@ const inputBookingFieldTypes = [
|
||||
"boolean",
|
||||
] as const;
|
||||
|
||||
export class NameFieldInput_2024_06_14 {
|
||||
const inputBookingFieldSlugs = ["name", "email", "title", "notes", "guests"] as const;
|
||||
|
||||
export class NameDefaultFieldInput_2024_06_14 {
|
||||
@IsIn(inputBookingFieldTypes)
|
||||
@DocsProperty({ example: "name", description: "only allowed value for type is `name`" })
|
||||
@DocsProperty({
|
||||
example: "name",
|
||||
description: "only allowed value for type is `name`",
|
||||
})
|
||||
type!: "name";
|
||||
|
||||
@IsString()
|
||||
@@ -48,9 +53,12 @@ export class NameFieldInput_2024_06_14 {
|
||||
disableOnPrefill?: boolean;
|
||||
}
|
||||
|
||||
export class EmailFieldInput_2024_06_14 {
|
||||
export class EmailDefaultFieldInput_2024_06_14 {
|
||||
@IsIn(inputBookingFieldTypes)
|
||||
@DocsProperty({ example: "email", description: "only allowed value for type is `email`" })
|
||||
@DocsProperty({
|
||||
example: "email",
|
||||
description: "only allowed value for type is `email`",
|
||||
})
|
||||
type!: "email";
|
||||
|
||||
@IsString()
|
||||
@@ -74,6 +82,170 @@ export class EmailFieldInput_2024_06_14 {
|
||||
})
|
||||
disableOnPrefill?: boolean;
|
||||
}
|
||||
|
||||
export class TitleDefaultFieldInput_2024_06_14 {
|
||||
@IsIn(inputBookingFieldSlugs)
|
||||
@DocsProperty({ example: "title", description: "only allowed value for type is `title`" })
|
||||
slug!: "title";
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
required?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
description:
|
||||
"If true show under event type settings but don't show this booking field in the Booker. If false show in both.",
|
||||
})
|
||||
hidden?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
label?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
placeholder?: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
type: Boolean,
|
||||
description:
|
||||
"Disable this booking field if the URL contains query parameter with key equal to the slug and prefill it with the provided value.\
|
||||
For example, if URL contains query parameter `&title=journey`,\
|
||||
the title field will be prefilled with this value and disabled.",
|
||||
})
|
||||
disableOnPrefill?: boolean;
|
||||
}
|
||||
|
||||
export class NotesDefaultFieldInput_2024_06_14 {
|
||||
@IsIn(inputBookingFieldSlugs)
|
||||
@DocsProperty({ example: "notes", description: "only allowed value for type is `notes`" })
|
||||
slug!: "notes";
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
required?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
description:
|
||||
"If true show under event type settings but don't show this booking field in the Booker. If false show in both.",
|
||||
})
|
||||
hidden?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
label?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
placeholder?: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
type: Boolean,
|
||||
description:
|
||||
"Disable this booking field if the URL contains query parameter with key equal to the slug and prefill it with the provided value.\
|
||||
For example, if URL contains query parameter `¬es=journey`,\
|
||||
the notes field will be prefilled with this value and disabled.",
|
||||
})
|
||||
disableOnPrefill?: boolean;
|
||||
}
|
||||
|
||||
export class GuestsDefaultFieldInput_2024_06_14 {
|
||||
@IsIn(inputBookingFieldSlugs)
|
||||
@DocsProperty({ example: "guests", description: "only allowed value for type is `guests`" })
|
||||
slug!: "guests";
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
required?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
description:
|
||||
"If true show under event type settings but don't show this booking field in the Booker. If false show in both.",
|
||||
})
|
||||
hidden?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
label?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
placeholder?: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
type: Boolean,
|
||||
description:
|
||||
"Disable this booking field if the URL contains query parameter with key equal to the slug and prefill it with the provided value.\
|
||||
For example, if URL contains query parameter `&[email protected]`,\
|
||||
the guests field will be prefilled with this value and disabled.",
|
||||
})
|
||||
disableOnPrefill?: boolean;
|
||||
}
|
||||
|
||||
export class RescheduleReasonDefaultFieldInput_2024_06_14 {
|
||||
@IsIn(inputBookingFieldSlugs)
|
||||
@DocsProperty({
|
||||
example: "rescheduleReason",
|
||||
description: "only allowed value for type is `rescheduleReason`",
|
||||
})
|
||||
slug!: "rescheduleReason";
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
required?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
description:
|
||||
"If true show under event type settings but don't show this booking field in the Booker. If false show in both.",
|
||||
})
|
||||
hidden?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
label?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional()
|
||||
placeholder?: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
type: Boolean,
|
||||
description:
|
||||
"Disable this booking field if the URL contains query parameter with key equal to the slug and prefill it with the provided value.\
|
||||
For example, if URL contains query parameter `&rescheduleReason=travel`,\
|
||||
the rescheduleReason field will be prefilled with this value and disabled.",
|
||||
})
|
||||
disableOnPrefill?: boolean;
|
||||
}
|
||||
|
||||
export class PhoneFieldInput_2024_06_14 {
|
||||
@IsIn(inputBookingFieldTypes)
|
||||
@DocsProperty({ example: "phone", description: "only allowed value for type is `phone`" })
|
||||
@@ -576,9 +748,16 @@ export class BooleanFieldInput_2024_06_14 {
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
type InputDefaultField_2024_06_14 =
|
||||
| NameDefaultFieldInput_2024_06_14
|
||||
| EmailDefaultFieldInput_2024_06_14
|
||||
| TitleDefaultFieldInput_2024_06_14
|
||||
| NotesDefaultFieldInput_2024_06_14
|
||||
| GuestsDefaultFieldInput_2024_06_14
|
||||
| RescheduleReasonDefaultFieldInput_2024_06_14;
|
||||
|
||||
export type InputBookingField_2024_06_14 =
|
||||
| NameFieldInput_2024_06_14
|
||||
| EmailFieldInput_2024_06_14
|
||||
| InputDefaultField_2024_06_14
|
||||
| PhoneFieldInput_2024_06_14
|
||||
| AddressFieldInput_2024_06_14
|
||||
| TextFieldInput_2024_06_14
|
||||
@@ -593,9 +772,13 @@ export type InputBookingField_2024_06_14 =
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class InputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterface {
|
||||
private classTypeMap: { [key: string]: new () => InputBookingField_2024_06_14 } = {
|
||||
name: NameFieldInput_2024_06_14,
|
||||
email: EmailFieldInput_2024_06_14,
|
||||
private classMap: { [key: string]: new () => InputBookingField_2024_06_14 } = {
|
||||
name: NameDefaultFieldInput_2024_06_14,
|
||||
email: EmailDefaultFieldInput_2024_06_14,
|
||||
title: TitleDefaultFieldInput_2024_06_14,
|
||||
notes: NotesDefaultFieldInput_2024_06_14,
|
||||
guests: GuestsDefaultFieldInput_2024_06_14,
|
||||
rescheduleReason: RescheduleReasonDefaultFieldInput_2024_06_14,
|
||||
phone: PhoneFieldInput_2024_06_14,
|
||||
address: AddressFieldInput_2024_06_14,
|
||||
text: TextFieldInput_2024_06_14,
|
||||
@@ -609,8 +792,6 @@ class InputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterf
|
||||
boolean: BooleanFieldInput_2024_06_14,
|
||||
};
|
||||
|
||||
private reservedSystemSlugs = ["location", "rescheduleReason", "attendeePhoneNumber"];
|
||||
|
||||
async validate(bookingFields: { type: string; slug: string }[]) {
|
||||
if (!Array.isArray(bookingFields)) {
|
||||
throw new BadRequestException(`'bookingFields' must be an array.`);
|
||||
@@ -623,20 +804,19 @@ class InputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterf
|
||||
const slugs: string[] = [];
|
||||
for (const field of bookingFields) {
|
||||
const { type, slug } = field;
|
||||
if (!type) {
|
||||
throw new BadRequestException(`Each booking field must have a 'type' property.`);
|
||||
}
|
||||
const fieldNeedsType =
|
||||
slug !== "title" && slug !== "notes" && slug !== "guests" && slug !== "rescheduleReason";
|
||||
|
||||
const notSystemEditableField = type !== "name" && type !== "email";
|
||||
if (notSystemEditableField && !slug) {
|
||||
throw new BadRequestException(`Each booking field must have a 'slug' property.`);
|
||||
}
|
||||
|
||||
if (this.reservedSystemSlugs.includes(slug)) {
|
||||
if (fieldNeedsType && !type) {
|
||||
throw new BadRequestException(
|
||||
`The slug '${slug}' is reserved and cannot be used, because it is a slug of a default booking field. Reserved slugs are: ${this.reservedSystemSlugs.join(
|
||||
", "
|
||||
)}`
|
||||
`All booking fields except ones with slug equal to title, notes, guests and rescheduleReason must have a 'type' property.`
|
||||
);
|
||||
}
|
||||
|
||||
const fieldNeedsSlug = type !== "name" && type !== "email";
|
||||
if (fieldNeedsSlug && !slug) {
|
||||
throw new BadRequestException(
|
||||
`Each booking field except ones with type equal to name and email must have a 'slug' property.`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -645,13 +825,15 @@ class InputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterf
|
||||
`Duplicate bookingFields slug '${slug}' found. All bookingFields slugs must be unique.`
|
||||
);
|
||||
}
|
||||
if (notSystemEditableField) {
|
||||
if (fieldNeedsSlug) {
|
||||
slugs.push(slug);
|
||||
}
|
||||
|
||||
const ClassType = this.classTypeMap[type];
|
||||
const ClassType = type ? this.classMap[type] : this.classMap[slug];
|
||||
if (!ClassType) {
|
||||
throw new BadRequestException(`Unsupported booking field type '${type}'.`);
|
||||
throw new BadRequestException(
|
||||
type ? `Unsupported booking field type '${type}'.` : `Unsupported booking field slug '${slug}'.`
|
||||
);
|
||||
}
|
||||
|
||||
const instance = plainToInstance(ClassType, field);
|
||||
@@ -682,3 +864,51 @@ export function ValidateInputBookingFields_2024_06_14(validationOptions?: Valida
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function isDefaultField(field: InputBookingField_2024_06_14): field is InputDefaultField_2024_06_14 {
|
||||
if (
|
||||
isDefaultNameField(field) ||
|
||||
isDefaultEmailField(field) ||
|
||||
isDefaultTitleField(field) ||
|
||||
isDefaultNotesField(field) ||
|
||||
isDefaultGuestsField(field) ||
|
||||
isDefaultRescheduleReasonField(field)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isDefaultNameField(field: InputBookingField_2024_06_14): field is NameDefaultFieldInput_2024_06_14 {
|
||||
return ("type" in field && field.type === "name") || ("slug" in field && field.slug === "name");
|
||||
}
|
||||
|
||||
function isDefaultEmailField(
|
||||
field: InputBookingField_2024_06_14
|
||||
): field is EmailDefaultFieldInput_2024_06_14 {
|
||||
return ("type" in field && field.type === "email") || ("slug" in field && field.slug === "email");
|
||||
}
|
||||
|
||||
function isDefaultTitleField(
|
||||
field: InputBookingField_2024_06_14
|
||||
): field is TitleDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "title";
|
||||
}
|
||||
|
||||
function isDefaultNotesField(
|
||||
field: InputBookingField_2024_06_14
|
||||
): field is NotesDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "notes";
|
||||
}
|
||||
|
||||
function isDefaultGuestsField(
|
||||
field: InputBookingField_2024_06_14
|
||||
): field is GuestsDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "guests";
|
||||
}
|
||||
|
||||
function isDefaultRescheduleReasonField(
|
||||
field: InputBookingField_2024_06_14
|
||||
): field is RescheduleReasonDefaultFieldInput_2024_06_14 {
|
||||
return "slug" in field && field.slug === "rescheduleReason";
|
||||
}
|
||||
+18
-6
@@ -26,16 +26,20 @@ import {
|
||||
AddressFieldInput_2024_06_14,
|
||||
BooleanFieldInput_2024_06_14,
|
||||
CheckboxGroupFieldInput_2024_06_14,
|
||||
EmailFieldInput_2024_06_14,
|
||||
EmailDefaultFieldInput_2024_06_14,
|
||||
GuestsDefaultFieldInput_2024_06_14,
|
||||
MultiEmailFieldInput_2024_06_14,
|
||||
MultiSelectFieldInput_2024_06_14,
|
||||
NameFieldInput_2024_06_14,
|
||||
NameDefaultFieldInput_2024_06_14,
|
||||
NotesDefaultFieldInput_2024_06_14,
|
||||
NumberFieldInput_2024_06_14,
|
||||
PhoneFieldInput_2024_06_14,
|
||||
RadioGroupFieldInput_2024_06_14,
|
||||
RescheduleReasonDefaultFieldInput_2024_06_14,
|
||||
SelectFieldInput_2024_06_14,
|
||||
TextAreaFieldInput_2024_06_14,
|
||||
TextFieldInput_2024_06_14,
|
||||
TitleDefaultFieldInput_2024_06_14,
|
||||
} from "./booking-fields.input";
|
||||
import type { InputBookingField_2024_06_14 } from "./booking-fields.input";
|
||||
import { ValidateInputBookingFields_2024_06_14 } from "./booking-fields.input";
|
||||
@@ -106,8 +110,12 @@ export const CREATE_EVENT_SLUG_EXAMPLE = "learn-the-secrets-of-masterchief";
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14,
|
||||
NameFieldInput_2024_06_14,
|
||||
EmailFieldInput_2024_06_14
|
||||
NameDefaultFieldInput_2024_06_14,
|
||||
EmailDefaultFieldInput_2024_06_14,
|
||||
TitleDefaultFieldInput_2024_06_14,
|
||||
NotesDefaultFieldInput_2024_06_14,
|
||||
GuestsDefaultFieldInput_2024_06_14,
|
||||
RescheduleReasonDefaultFieldInput_2024_06_14
|
||||
)
|
||||
export class CreateEventTypeInput_2024_06_14 {
|
||||
@IsInt()
|
||||
@@ -166,8 +174,12 @@ export class CreateEventTypeInput_2024_06_14 {
|
||||
description:
|
||||
"Custom fields that can be added to the booking form when the event is booked by someone. By default booking form has name and email field.",
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(NameFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(EmailFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(NameDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(EmailDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(TitleDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(NotesDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(GuestsDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(RescheduleReasonDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(PhoneFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AddressFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(TextFieldInput_2024_06_14) },
|
||||
|
||||
+18
-6
@@ -24,16 +24,20 @@ import {
|
||||
AddressFieldInput_2024_06_14,
|
||||
BooleanFieldInput_2024_06_14,
|
||||
CheckboxGroupFieldInput_2024_06_14,
|
||||
EmailFieldInput_2024_06_14,
|
||||
EmailDefaultFieldInput_2024_06_14,
|
||||
GuestsDefaultFieldInput_2024_06_14,
|
||||
MultiEmailFieldInput_2024_06_14,
|
||||
MultiSelectFieldInput_2024_06_14,
|
||||
NameFieldInput_2024_06_14,
|
||||
NameDefaultFieldInput_2024_06_14,
|
||||
NotesDefaultFieldInput_2024_06_14,
|
||||
NumberFieldInput_2024_06_14,
|
||||
PhoneFieldInput_2024_06_14,
|
||||
RadioGroupFieldInput_2024_06_14,
|
||||
RescheduleReasonDefaultFieldInput_2024_06_14,
|
||||
SelectFieldInput_2024_06_14,
|
||||
TextAreaFieldInput_2024_06_14,
|
||||
TextFieldInput_2024_06_14,
|
||||
TitleDefaultFieldInput_2024_06_14,
|
||||
ValidateInputBookingFields_2024_06_14,
|
||||
} from "./booking-fields.input";
|
||||
import type { BookingLimitsCount_2024_06_14 } from "./booking-limits-count.input";
|
||||
@@ -104,8 +108,12 @@ import { Seats_2024_06_14 } from "./seats.input";
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14,
|
||||
NameFieldInput_2024_06_14,
|
||||
EmailFieldInput_2024_06_14
|
||||
NameDefaultFieldInput_2024_06_14,
|
||||
EmailDefaultFieldInput_2024_06_14,
|
||||
TitleDefaultFieldInput_2024_06_14,
|
||||
NotesDefaultFieldInput_2024_06_14,
|
||||
GuestsDefaultFieldInput_2024_06_14,
|
||||
RescheduleReasonDefaultFieldInput_2024_06_14
|
||||
)
|
||||
export class UpdateEventTypeInput_2024_06_14 {
|
||||
@IsOptional()
|
||||
@@ -167,8 +175,12 @@ export class UpdateEventTypeInput_2024_06_14 {
|
||||
description:
|
||||
"Custom fields that can be added to the booking form when the event is booked by someone. By default booking form has name and email field.",
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(NameFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(EmailFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(NameDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(EmailDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(TitleDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(NotesDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(GuestsDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(RescheduleReasonDefaultFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(PhoneFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AddressFieldInput_2024_06_14) },
|
||||
{ $ref: getSchemaPath(TextFieldInput_2024_06_14) },
|
||||
|
||||
+32
-41
@@ -1,4 +1,4 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { Logger } from "@nestjs/common";
|
||||
import { ApiProperty, ApiProperty as DocsProperty } from "@nestjs/swagger";
|
||||
import { plainToInstance } from "class-transformer";
|
||||
import { IsBoolean, IsOptional, IsString } from "class-validator";
|
||||
@@ -17,11 +17,15 @@ import {
|
||||
CheckboxGroupFieldInput_2024_06_14,
|
||||
RadioGroupFieldInput_2024_06_14,
|
||||
BooleanFieldInput_2024_06_14,
|
||||
NameFieldInput_2024_06_14,
|
||||
EmailFieldInput_2024_06_14,
|
||||
NameDefaultFieldInput_2024_06_14,
|
||||
EmailDefaultFieldInput_2024_06_14,
|
||||
GuestsDefaultFieldInput_2024_06_14,
|
||||
NotesDefaultFieldInput_2024_06_14,
|
||||
RescheduleReasonDefaultFieldInput_2024_06_14,
|
||||
TitleDefaultFieldInput_2024_06_14,
|
||||
} from "../inputs";
|
||||
|
||||
export class NameDefaultFieldOutput_2024_06_14 extends NameFieldInput_2024_06_14 {
|
||||
export class NameDefaultFieldOutput_2024_06_14 extends NameDefaultFieldInput_2024_06_14 {
|
||||
@IsBoolean()
|
||||
@DocsProperty({
|
||||
description: "This property is always true because it's a default field",
|
||||
@@ -47,7 +51,7 @@ export class NameDefaultFieldOutput_2024_06_14 extends NameFieldInput_2024_06_14
|
||||
required!: boolean;
|
||||
}
|
||||
|
||||
export class EmailDefaultFieldOutput_2024_06_14 extends EmailFieldInput_2024_06_14 {
|
||||
export class EmailDefaultFieldOutput_2024_06_14 extends EmailDefaultFieldInput_2024_06_14 {
|
||||
@IsBoolean()
|
||||
@DocsProperty({
|
||||
description: "This property is always true because it's a default field",
|
||||
@@ -108,7 +112,7 @@ export class LocationDefaultFieldOutput_2024_06_14 {
|
||||
hidden!: boolean;
|
||||
}
|
||||
|
||||
export class RescheduleReasonDefaultFieldOutput_2024_06_14 {
|
||||
export class RescheduleReasonDefaultFieldOutput_2024_06_14 extends RescheduleReasonDefaultFieldInput_2024_06_14 {
|
||||
@IsBoolean()
|
||||
@DocsProperty({
|
||||
description: "This property is always true because it's a default field",
|
||||
@@ -161,7 +165,7 @@ export class RescheduleReasonDefaultFieldOutput_2024_06_14 {
|
||||
disableOnPrefill!: boolean;
|
||||
}
|
||||
|
||||
export class TitleDefaultFieldOutput_2024_06_14 {
|
||||
export class TitleDefaultFieldOutput_2024_06_14 extends TitleDefaultFieldInput_2024_06_14 {
|
||||
@IsBoolean()
|
||||
@DocsProperty({
|
||||
description: "This property is always true because it's a default field",
|
||||
@@ -214,7 +218,7 @@ export class TitleDefaultFieldOutput_2024_06_14 {
|
||||
disableOnPrefill!: boolean;
|
||||
}
|
||||
|
||||
export class NotesDefaultFieldOutput_2024_06_14 {
|
||||
export class NotesDefaultFieldOutput_2024_06_14 extends NotesDefaultFieldInput_2024_06_14 {
|
||||
@IsBoolean()
|
||||
@DocsProperty({
|
||||
description: "This property is always true because it's a default field",
|
||||
@@ -267,7 +271,7 @@ export class NotesDefaultFieldOutput_2024_06_14 {
|
||||
disableOnPrefill!: boolean;
|
||||
}
|
||||
|
||||
export class GuestsDefaultFieldOutput_2024_06_14 {
|
||||
export class GuestsDefaultFieldOutput_2024_06_14 extends GuestsDefaultFieldInput_2024_06_14 {
|
||||
@IsBoolean()
|
||||
@DocsProperty({
|
||||
description: "This property is always true because it's a default field",
|
||||
@@ -567,6 +571,8 @@ export type CustomFieldOutput_2024_06_14 =
|
||||
| RadioGroupFieldOutput_2024_06_14
|
||||
| BooleanFieldOutput_2024_06_14;
|
||||
|
||||
export type KnownBookingField_2024_06_14 = DefaultFieldOutput_2024_06_14 | CustomFieldOutput_2024_06_14;
|
||||
|
||||
export type OutputBookingField_2024_06_14 =
|
||||
| DefaultFieldOutput_2024_06_14
|
||||
| CustomFieldOutput_2024_06_14
|
||||
@@ -574,6 +580,8 @@ export type OutputBookingField_2024_06_14 =
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterface {
|
||||
private readonly logger = new Logger("OutputBookingFieldValidator_2024_06_14");
|
||||
|
||||
private defaultOutputNameMap: { [key: string]: new () => DefaultFieldOutput_2024_06_14 } = {
|
||||
name: NameDefaultFieldOutput_2024_06_14,
|
||||
email: EmailDefaultFieldOutput_2024_06_14,
|
||||
@@ -600,34 +608,7 @@ class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInter
|
||||
};
|
||||
|
||||
async validate(bookingFields: OutputBookingField_2024_06_14[]) {
|
||||
if (!Array.isArray(bookingFields)) {
|
||||
throw new BadRequestException(`'bookingFields' must be an array.`);
|
||||
}
|
||||
|
||||
if (!bookingFields.length) {
|
||||
throw new BadRequestException(`'bookingFields' must contain at least 1 booking field.`);
|
||||
}
|
||||
|
||||
const slugs: string[] = [];
|
||||
for (const field of bookingFields) {
|
||||
const { type, slug } = field;
|
||||
if (!type) {
|
||||
throw new BadRequestException(`Each booking field must have a 'type' property.`);
|
||||
}
|
||||
|
||||
if (!slug) {
|
||||
throw new BadRequestException(`Each booking field must have a 'slug' property.`);
|
||||
}
|
||||
|
||||
if (slugs.includes(slug)) {
|
||||
throw new BadRequestException(
|
||||
`Duplicate bookingFields slug '${slug}' found. All bookingFields slugs must be unique.`
|
||||
);
|
||||
}
|
||||
if (slug !== "unknown") {
|
||||
slugs.push(slug);
|
||||
}
|
||||
|
||||
if (this.isUnknownField(field)) {
|
||||
await this.validateUnknownField(field);
|
||||
} else if (this.isDefaultField(field)) {
|
||||
@@ -653,35 +634,45 @@ class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInter
|
||||
const errors = await validate(instance);
|
||||
if (errors.length > 0) {
|
||||
const message = errors.flatMap((error) => Object.values(error.constraints || {})).join(", ");
|
||||
throw new BadRequestException(`Validation failed for ${field.slug} booking field: ${message}`);
|
||||
this.logger.error(
|
||||
`OutputBookingFieldValidator_2024_06_14: Validation failed for unknown booking field: ${message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async validateDefaultField(field: DefaultFieldOutput_2024_06_14) {
|
||||
const ClassType = this.defaultOutputNameMap[field.slug];
|
||||
if (!ClassType) {
|
||||
throw new BadRequestException(`Unsupported default booking field slug '${field.slug}'.`);
|
||||
this.logger.error(
|
||||
`OutputBookingFieldValidator_2024_06_14: Unsupported default booking field slug '${field.slug}'.`
|
||||
);
|
||||
}
|
||||
|
||||
const instance = plainToInstance(ClassType, field);
|
||||
const errors = await validate(instance);
|
||||
if (errors.length > 0) {
|
||||
const message = errors.flatMap((error) => Object.values(error.constraints || {})).join(", ");
|
||||
throw new BadRequestException(`Validation failed for ${field.slug} booking field: ${message}`);
|
||||
this.logger.error(
|
||||
`OutputBookingFieldValidator_2024_06_14: Validation failed for ${field.slug} booking field: ${message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async validateCustomField(field: CustomFieldOutput_2024_06_14) {
|
||||
const ClassType = this.customOutputTypeMap[field.type];
|
||||
if (!ClassType) {
|
||||
throw new BadRequestException(`Unsupported booking field type '${field.type}'.`);
|
||||
this.logger.error(
|
||||
`OutputBookingFieldValidator_2024_06_14: Unsupported custom booking field type '${field.type}'.`
|
||||
);
|
||||
}
|
||||
|
||||
const instance = plainToInstance(ClassType, field);
|
||||
const errors = await validate(instance);
|
||||
if (errors.length > 0) {
|
||||
const message = errors.flatMap((error) => Object.values(error.constraints || {})).join(", ");
|
||||
throw new BadRequestException(`Validation failed for ${field.type} booking field: ${message}`);
|
||||
this.logger.error(
|
||||
`OutputBookingFieldValidator_2024_06_14: Validation failed for ${field.type} booking field: ${message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import type {
|
||||
transformIntervalLimitsApiToInternal,
|
||||
transformRecurrenceApiToInternal,
|
||||
transformSeatsApiToInternal,
|
||||
transformBookingFieldsApiRequestToInternal,
|
||||
transformBookingFieldsApiToInternal,
|
||||
InternalLocationsSchema,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
@@ -33,7 +33,7 @@ export type InputEventTransformed_2024_06_14 = Omit<
|
||||
eventName?: string;
|
||||
bookingLimits?: ReturnType<typeof transformIntervalLimitsApiToInternal>;
|
||||
locations?: z.infer<typeof InternalLocationsSchema>;
|
||||
bookingFields?: ReturnType<typeof transformBookingFieldsApiRequestToInternal>;
|
||||
bookingFields?: ReturnType<typeof transformBookingFieldsApiToInternal>;
|
||||
durationLimits?: ReturnType<typeof transformIntervalLimitsApiToInternal>;
|
||||
recurringEvent?: ReturnType<typeof transformRecurrenceApiToInternal>;
|
||||
eventTypeColor?: ReturnType<typeof transformEventColorsApiToInternal>;
|
||||
|
||||
Reference in new issue
Block a user