fix: v2 event type locations (#17288)
* refactor: split internal locations in separate file * refactor: rename TransformedLocationsSchema to InternalLocationsSchema * feat: add missing locations in internal schema * refactor: explicit input locations only for input * refactor: explicit output locations only for output * fix: v2 * fix: atoms * test: internal to api locations transformation * e2e tests * upgrade platform libraries
This commit is contained in:
1 parent
50a41109d0
commit
c629d08a9c
20 files changed
+1087
-280
No files matched your search
+18
-1
@@ -14,6 +14,7 @@ import type {
|
||||
CustomFieldOutput_2024_06_14,
|
||||
EmailDefaultFieldOutput_2024_06_14,
|
||||
EventTypeOutput_2024_06_14,
|
||||
InputLocation_2024_06_14,
|
||||
NameDefaultFieldOutput_2024_06_14,
|
||||
TeamEventTypeOutput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
@@ -199,7 +200,9 @@ function isDefaultEvent(eventSlug: string) {
|
||||
}
|
||||
|
||||
function getLocations(locations: EventTypeOutput_2024_06_14["locations"]) {
|
||||
const transformed = transformLocationsApiToInternal(locations);
|
||||
const transformed = transformLocationsApiToInternal(
|
||||
locations.filter((location) => isAtomSupportedLocation(location))
|
||||
);
|
||||
|
||||
const withPrivateHidden = transformed.map((location) => {
|
||||
const { displayLocationPublicly, type } = location;
|
||||
@@ -224,6 +227,20 @@ function getLocations(locations: EventTypeOutput_2024_06_14["locations"]) {
|
||||
return withPrivateHidden;
|
||||
}
|
||||
|
||||
function isAtomSupportedLocation(
|
||||
location: EventTypeOutput_2024_06_14["locations"][number]
|
||||
): location is InputLocation_2024_06_14 {
|
||||
return (
|
||||
location.type === "address" ||
|
||||
location.type === "attendeeAddress" ||
|
||||
location.type === "link" ||
|
||||
location.type === "phone" ||
|
||||
location.type === "attendeePhone" ||
|
||||
location.type === "attendeeDefined" ||
|
||||
(location.type === "integration" && location.integration === "cal-video")
|
||||
);
|
||||
}
|
||||
|
||||
function getBookingFields(
|
||||
bookingFields: EventTypeOutput_2024_06_14["bookingFields"],
|
||||
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined
|
||||
|
||||
@@ -126,7 +126,8 @@ export {
|
||||
transformEventTypeColorsInternalToApi,
|
||||
transformSeatsInternalToApi,
|
||||
// note(Lauris): schemas
|
||||
TransformedLocationsSchema,
|
||||
InternalLocationsSchema,
|
||||
InternalLocationSchema,
|
||||
BookingFieldsSchema,
|
||||
// note(Lauris): constants
|
||||
systemBeforeFieldName,
|
||||
@@ -140,6 +141,7 @@ export type {
|
||||
CustomField,
|
||||
NameSystemField,
|
||||
EmailSystemField,
|
||||
InternalLocation,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
export { parseBookingLimit, parseEventTypeColor } from "@calcom/lib";
|
||||
|
||||
+23
-23
@@ -54,16 +54,16 @@ import { DestinationCalendar_2024_06_14 } from "./destination-calendar.input";
|
||||
import { Disabled_2024_06_14 } from "./disabled.input";
|
||||
import { EventTypeColor_2024_06_14 } from "./event-type-color.input";
|
||||
import {
|
||||
AddressLocation_2024_06_14,
|
||||
AttendeeAddressLocation_2024_06_14,
|
||||
AttendeeDefinedLocation_2024_06_14,
|
||||
AttendeePhoneLocation_2024_06_14,
|
||||
IntegrationLocation_2024_06_14,
|
||||
LinkLocation_2024_06_14,
|
||||
PhoneLocation_2024_06_14,
|
||||
InputAddressLocation_2024_06_14,
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputIntegrationLocation_2024_06_14,
|
||||
InputLinkLocation_2024_06_14,
|
||||
InputPhoneLocation_2024_06_14,
|
||||
ValidateLocations_2024_06_14,
|
||||
} from "./locations.input";
|
||||
import type { Location_2024_06_14 } from "./locations.input";
|
||||
import type { InputLocation_2024_06_14 } from "./locations.input";
|
||||
import { Recurrence_2024_06_14 } from "./recurrence.input";
|
||||
import { Seats_2024_06_14 } from "./seats.input";
|
||||
|
||||
@@ -74,10 +74,10 @@ export const CREATE_EVENT_DESCRIPTION_EXAMPLE =
|
||||
export const CREATE_EVENT_SLUG_EXAMPLE = "learn-the-secrets-of-masterchief";
|
||||
|
||||
@ApiExtraModels(
|
||||
AddressLocation_2024_06_14,
|
||||
LinkLocation_2024_06_14,
|
||||
IntegrationLocation_2024_06_14,
|
||||
PhoneLocation_2024_06_14,
|
||||
InputAddressLocation_2024_06_14,
|
||||
InputLinkLocation_2024_06_14,
|
||||
InputIntegrationLocation_2024_06_14,
|
||||
InputPhoneLocation_2024_06_14,
|
||||
PhoneFieldInput_2024_06_14,
|
||||
AddressFieldInput_2024_06_14,
|
||||
TextFieldInput_2024_06_14,
|
||||
@@ -98,9 +98,9 @@ export const CREATE_EVENT_SLUG_EXAMPLE = "learn-the-secrets-of-masterchief";
|
||||
Recurrence_2024_06_14,
|
||||
BaseConfirmationPolicy_2024_06_14,
|
||||
Seats_2024_06_14,
|
||||
AttendeeAddressLocation_2024_06_14,
|
||||
AttendeePhoneLocation_2024_06_14,
|
||||
AttendeeDefinedLocation_2024_06_14
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14
|
||||
)
|
||||
export class CreateEventTypeInput_2024_06_14 {
|
||||
@IsInt()
|
||||
@@ -127,18 +127,18 @@ export class CreateEventTypeInput_2024_06_14 {
|
||||
description:
|
||||
"Locations where the event will take place. If not provided, cal video link will be used as the location.",
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(AddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(LinkLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(IntegrationLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(PhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AttendeeAddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AttendeePhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AttendeeDefinedLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputLinkLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputIntegrationLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputPhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAttendeeAddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAttendeePhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAttendeeDefinedLocation_2024_06_14) },
|
||||
],
|
||||
type: "array",
|
||||
})
|
||||
@Type(() => Object)
|
||||
locations?: Location_2024_06_14[];
|
||||
locations?: InputLocation_2024_06_14[];
|
||||
|
||||
@IsOptional()
|
||||
@ValidateInputBookingFields_2024_06_14()
|
||||
|
||||
+33
-33
@@ -5,7 +5,7 @@ import { IsString, IsUrl, IsIn, IsPhoneNumber, IsBoolean } from "class-validator
|
||||
import type { ValidationOptions, ValidatorConstraintInterface } from "class-validator";
|
||||
import { registerDecorator, validate, ValidatorConstraint } from "class-validator";
|
||||
|
||||
const locations = [
|
||||
export const inputLocations = [
|
||||
"address",
|
||||
"link",
|
||||
"integration",
|
||||
@@ -15,8 +15,8 @@ const locations = [
|
||||
"attendeeDefined",
|
||||
] as const;
|
||||
|
||||
export class AddressLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
export class InputAddressLocation_2024_06_14 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({ example: "address", description: "only allowed value for type is `address`" })
|
||||
type!: "address";
|
||||
|
||||
@@ -29,8 +29,8 @@ export class AddressLocation_2024_06_14 {
|
||||
public!: boolean;
|
||||
}
|
||||
|
||||
export class LinkLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
export class InputLinkLocation_2024_06_14 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({ example: "link", description: "only allowed value for type is `link`" })
|
||||
type!: "link";
|
||||
|
||||
@@ -46,8 +46,8 @@ export class LinkLocation_2024_06_14 {
|
||||
const integrations = ["cal-video"] as const;
|
||||
export type Integration_2024_06_14 = (typeof integrations)[number];
|
||||
|
||||
export class IntegrationLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
export class InputIntegrationLocation_2024_06_14 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({ example: "integration", description: "only allowed value for type is `integration`" })
|
||||
type!: "integration";
|
||||
|
||||
@@ -56,8 +56,8 @@ export class IntegrationLocation_2024_06_14 {
|
||||
integration!: Integration_2024_06_14;
|
||||
}
|
||||
|
||||
export class PhoneLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
export class InputPhoneLocation_2024_06_14 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({ example: "phone", description: "only allowed value for type is `phone`" })
|
||||
type!: "phone";
|
||||
|
||||
@@ -70,22 +70,22 @@ export class PhoneLocation_2024_06_14 {
|
||||
public!: boolean;
|
||||
}
|
||||
|
||||
export class AttendeeAddressLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
export class InputAttendeeAddressLocation_2024_06_14 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "attendeeAddress",
|
||||
description: "only allowed value for type is `attendeeAddress`",
|
||||
})
|
||||
type!: "attendeeAddress";
|
||||
}
|
||||
export class AttendeePhoneLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
export class InputAttendeePhoneLocation_2024_06_14 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({ example: "attendeePhone", description: "only allowed value for type is `attendeePhone`" })
|
||||
type!: "attendeePhone";
|
||||
}
|
||||
|
||||
export class AttendeeDefinedLocation_2024_06_14 {
|
||||
@IsIn(locations)
|
||||
export class InputAttendeeDefinedLocation_2024_06_14 {
|
||||
@IsIn(inputLocations)
|
||||
@DocsProperty({
|
||||
example: "attendeeDefined",
|
||||
description: "only allowed value for type is `attendeeDefined`",
|
||||
@@ -93,25 +93,25 @@ export class AttendeeDefinedLocation_2024_06_14 {
|
||||
type!: "attendeeDefined";
|
||||
}
|
||||
|
||||
export type Location_2024_06_14 =
|
||||
| AddressLocation_2024_06_14
|
||||
| LinkLocation_2024_06_14
|
||||
| IntegrationLocation_2024_06_14
|
||||
| PhoneLocation_2024_06_14
|
||||
| AttendeeAddressLocation_2024_06_14
|
||||
| AttendeePhoneLocation_2024_06_14
|
||||
| AttendeeDefinedLocation_2024_06_14;
|
||||
export type InputLocation_2024_06_14 =
|
||||
| InputAddressLocation_2024_06_14
|
||||
| InputLinkLocation_2024_06_14
|
||||
| InputIntegrationLocation_2024_06_14
|
||||
| InputPhoneLocation_2024_06_14
|
||||
| InputAttendeeAddressLocation_2024_06_14
|
||||
| InputAttendeePhoneLocation_2024_06_14
|
||||
| InputAttendeeDefinedLocation_2024_06_14;
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class LocationValidator_2024_06_14 implements ValidatorConstraintInterface {
|
||||
private classTypeMap: { [key: string]: new () => Location_2024_06_14 } = {
|
||||
address: AddressLocation_2024_06_14,
|
||||
link: LinkLocation_2024_06_14,
|
||||
integration: IntegrationLocation_2024_06_14,
|
||||
phone: PhoneLocation_2024_06_14,
|
||||
attendeePhone: AttendeePhoneLocation_2024_06_14,
|
||||
attendeeAddress: AttendeeAddressLocation_2024_06_14,
|
||||
attendeeDefined: AttendeeDefinedLocation_2024_06_14,
|
||||
class InputLocationValidator_2024_06_14 implements ValidatorConstraintInterface {
|
||||
private classTypeMap: { [key: string]: new () => InputLocation_2024_06_14 } = {
|
||||
address: InputAddressLocation_2024_06_14,
|
||||
link: InputLinkLocation_2024_06_14,
|
||||
integration: InputIntegrationLocation_2024_06_14,
|
||||
phone: InputPhoneLocation_2024_06_14,
|
||||
attendeePhone: InputAttendeePhoneLocation_2024_06_14,
|
||||
attendeeAddress: InputAttendeeAddressLocation_2024_06_14,
|
||||
attendeeDefined: InputAttendeeDefinedLocation_2024_06_14,
|
||||
};
|
||||
|
||||
async validate(locations: { type: string }[]) {
|
||||
@@ -160,7 +160,7 @@ export function ValidateLocations_2024_06_14(validationOptions?: ValidationOptio
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: new LocationValidator_2024_06_14(),
|
||||
validator: new InputLocationValidator_2024_06_14(),
|
||||
});
|
||||
};
|
||||
}
|
||||
+23
-23
@@ -50,24 +50,24 @@ import { DestinationCalendar_2024_06_14 } from "./destination-calendar.input";
|
||||
import { Disabled_2024_06_14 } from "./disabled.input";
|
||||
import { EventTypeColor_2024_06_14 } from "./event-type-color.input";
|
||||
import {
|
||||
AddressLocation_2024_06_14,
|
||||
AttendeeAddressLocation_2024_06_14,
|
||||
AttendeeDefinedLocation_2024_06_14,
|
||||
AttendeePhoneLocation_2024_06_14,
|
||||
IntegrationLocation_2024_06_14,
|
||||
LinkLocation_2024_06_14,
|
||||
PhoneLocation_2024_06_14,
|
||||
InputAddressLocation_2024_06_14,
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputIntegrationLocation_2024_06_14,
|
||||
InputLinkLocation_2024_06_14,
|
||||
InputPhoneLocation_2024_06_14,
|
||||
ValidateLocations_2024_06_14,
|
||||
} from "./locations.input";
|
||||
import type { Location_2024_06_14 } from "./locations.input";
|
||||
import type { InputLocation_2024_06_14 } from "./locations.input";
|
||||
import { Recurrence_2024_06_14 } from "./recurrence.input";
|
||||
import { Seats_2024_06_14 } from "./seats.input";
|
||||
|
||||
@ApiExtraModels(
|
||||
AddressLocation_2024_06_14,
|
||||
LinkLocation_2024_06_14,
|
||||
IntegrationLocation_2024_06_14,
|
||||
PhoneLocation_2024_06_14,
|
||||
InputAddressLocation_2024_06_14,
|
||||
InputLinkLocation_2024_06_14,
|
||||
InputIntegrationLocation_2024_06_14,
|
||||
InputPhoneLocation_2024_06_14,
|
||||
PhoneFieldInput_2024_06_14,
|
||||
AddressFieldInput_2024_06_14,
|
||||
TextFieldInput_2024_06_14,
|
||||
@@ -88,9 +88,9 @@ import { Seats_2024_06_14 } from "./seats.input";
|
||||
Recurrence_2024_06_14,
|
||||
BaseConfirmationPolicy_2024_06_14,
|
||||
Seats_2024_06_14,
|
||||
AttendeeAddressLocation_2024_06_14,
|
||||
AttendeePhoneLocation_2024_06_14,
|
||||
AttendeeDefinedLocation_2024_06_14
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14
|
||||
)
|
||||
export class UpdateEventTypeInput_2024_06_14 {
|
||||
@IsOptional()
|
||||
@@ -120,18 +120,18 @@ export class UpdateEventTypeInput_2024_06_14 {
|
||||
description:
|
||||
"Locations where the event will take place. If not provided, cal video link will be used as the location.",
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(AddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(LinkLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(IntegrationLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(PhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AttendeeAddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AttendeePhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(AttendeeDefinedLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputLinkLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputIntegrationLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputPhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAttendeeAddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAttendeePhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(InputAttendeeDefinedLocation_2024_06_14) },
|
||||
],
|
||||
type: "array",
|
||||
})
|
||||
@Type(() => Object)
|
||||
locations?: Location_2024_06_14[];
|
||||
locations?: InputLocation_2024_06_14[];
|
||||
|
||||
@IsOptional()
|
||||
@ValidateInputBookingFields_2024_06_14()
|
||||
|
||||
+25
-22
@@ -11,11 +11,7 @@ import {
|
||||
ValidateNested,
|
||||
} from "class-validator";
|
||||
|
||||
import type {
|
||||
Location_2024_06_14,
|
||||
BookingWindow_2024_06_14,
|
||||
BookingLimitsDuration_2024_06_14,
|
||||
} from "../inputs";
|
||||
import type { BookingWindow_2024_06_14, BookingLimitsDuration_2024_06_14 } from "../inputs";
|
||||
import {
|
||||
EventTypeColor_2024_06_14,
|
||||
Seats_2024_06_14,
|
||||
@@ -30,13 +26,6 @@ import { BookerLayouts_2024_06_14 } from "../inputs/booker-layouts.input";
|
||||
import type { BookingLimitsCount_2024_06_14 } from "../inputs/booking-limits-count.input";
|
||||
import type { ConfirmationPolicy_2024_06_14 } from "../inputs/confirmation-policy.input";
|
||||
import { DestinationCalendar_2024_06_14 } from "../inputs/destination-calendar.input";
|
||||
import {
|
||||
AddressLocation_2024_06_14,
|
||||
IntegrationLocation_2024_06_14,
|
||||
LinkLocation_2024_06_14,
|
||||
PhoneLocation_2024_06_14,
|
||||
ValidateLocations_2024_06_14,
|
||||
} from "../inputs/locations.input";
|
||||
import {
|
||||
EmailDefaultFieldOutput_2024_06_14,
|
||||
NameDefaultFieldOutput_2024_06_14,
|
||||
@@ -59,6 +48,16 @@ import {
|
||||
} from "../outputs/booking-fields.output";
|
||||
import type { OutputBookingField_2024_06_14 } from "./booking-fields.output";
|
||||
import { ValidateOutputBookingFields_2024_06_14 } from "./booking-fields.output";
|
||||
import type { OutputLocation_2024_06_14 } from "./locations.output";
|
||||
import {
|
||||
OutputAddressLocation_2024_06_14,
|
||||
OutputConferencingLocation_2024_06_14,
|
||||
OutputIntegrationLocation_2024_06_14,
|
||||
OutputLinkLocation_2024_06_14,
|
||||
OutputPhoneLocation_2024_06_14,
|
||||
OutputUnknownLocation_2024_06_14,
|
||||
ValidateOutputLocations_2024_06_14,
|
||||
} from "./locations.output";
|
||||
|
||||
enum SchedulingTypeEnum {
|
||||
ROUND_ROBIN = "ROUND_ROBIN",
|
||||
@@ -95,10 +94,12 @@ class User_2024_06_14 {
|
||||
}
|
||||
|
||||
@ApiExtraModels(
|
||||
AddressLocation_2024_06_14,
|
||||
LinkLocation_2024_06_14,
|
||||
IntegrationLocation_2024_06_14,
|
||||
PhoneLocation_2024_06_14,
|
||||
OutputAddressLocation_2024_06_14,
|
||||
OutputLinkLocation_2024_06_14,
|
||||
OutputIntegrationLocation_2024_06_14,
|
||||
OutputPhoneLocation_2024_06_14,
|
||||
OutputConferencingLocation_2024_06_14,
|
||||
OutputUnknownLocation_2024_06_14,
|
||||
EmailDefaultFieldOutput_2024_06_14,
|
||||
NameDefaultFieldOutput_2024_06_14,
|
||||
LocationDefaultFieldOutput_2024_06_14,
|
||||
@@ -146,18 +147,20 @@ class BaseEventTypeOutput_2024_06_14 {
|
||||
})
|
||||
description!: string;
|
||||
|
||||
@ValidateLocations_2024_06_14()
|
||||
@ValidateOutputLocations_2024_06_14()
|
||||
@DocsProperty({
|
||||
oneOf: [
|
||||
{ $ref: getSchemaPath(AddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(LinkLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(IntegrationLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(PhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(OutputAddressLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(OutputLinkLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(OutputIntegrationLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(OutputPhoneLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(OutputConferencingLocation_2024_06_14) },
|
||||
{ $ref: getSchemaPath(OutputUnknownLocation_2024_06_14) },
|
||||
],
|
||||
type: "array",
|
||||
})
|
||||
@Type(() => Object)
|
||||
locations!: Location_2024_06_14[];
|
||||
locations!: OutputLocation_2024_06_14[];
|
||||
|
||||
@ValidateOutputBookingFields_2024_06_14()
|
||||
@DocsProperty()
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./event-type.output";
|
||||
export * from "./booking-fields.output";
|
||||
export * from "./locations.output";
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { ApiProperty as DocsProperty } from "@nestjs/swagger";
|
||||
import { plainToInstance } from "class-transformer";
|
||||
import { IsUrl, IsIn, IsOptional, IsNumber, IsString } from "class-validator";
|
||||
import type { ValidationOptions, ValidatorConstraintInterface } from "class-validator";
|
||||
import { registerDecorator, validate, ValidatorConstraint } from "class-validator";
|
||||
|
||||
import {
|
||||
InputAddressLocation_2024_06_14,
|
||||
InputAttendeeAddressLocation_2024_06_14,
|
||||
InputAttendeeDefinedLocation_2024_06_14,
|
||||
InputAttendeePhoneLocation_2024_06_14,
|
||||
InputLinkLocation_2024_06_14,
|
||||
inputLocations,
|
||||
InputPhoneLocation_2024_06_14,
|
||||
} from "../inputs";
|
||||
|
||||
const outputLocations = [...inputLocations, "conferencing", "unknown"] as const;
|
||||
|
||||
export class OutputAddressLocation_2024_06_14 extends InputAddressLocation_2024_06_14 {}
|
||||
export class OutputLinkLocation_2024_06_14 extends InputLinkLocation_2024_06_14 {}
|
||||
export class OutputPhoneLocation_2024_06_14 extends InputPhoneLocation_2024_06_14 {}
|
||||
export class OutputAttendeeAddressLocation_2024_06_14 extends InputAttendeeAddressLocation_2024_06_14 {}
|
||||
export class OutputAttendeePhoneLocation_2024_06_14 extends InputAttendeePhoneLocation_2024_06_14 {}
|
||||
export class OutputAttendeeDefinedLocation_2024_06_14 extends InputAttendeeDefinedLocation_2024_06_14 {}
|
||||
|
||||
const integrationsValues = [
|
||||
"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 OutputIntegration_2024_06_14 = (typeof integrationsValues)[number];
|
||||
|
||||
export class OutputIntegrationLocation_2024_06_14 {
|
||||
@IsIn(outputLocations)
|
||||
@DocsProperty({ example: "integration", description: "only allowed value for type is `integration`" })
|
||||
type!: "integration";
|
||||
|
||||
@IsIn(integrationsValues)
|
||||
@DocsProperty({ example: integrationsValues[0], enum: integrationsValues })
|
||||
integration!: OutputIntegration_2024_06_14;
|
||||
|
||||
@IsUrl()
|
||||
@IsOptional()
|
||||
link?: string;
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
credentialId?: number;
|
||||
}
|
||||
|
||||
export class OutputConferencingLocation_2024_06_14 {
|
||||
@IsIn(outputLocations)
|
||||
@DocsProperty({ example: "conferencing", description: "only allowed value for type is `conferencing`" })
|
||||
type!: "conferencing";
|
||||
}
|
||||
|
||||
export class OutputUnknownLocation_2024_06_14 {
|
||||
@IsIn(outputLocations)
|
||||
@DocsProperty({ example: "unknown", description: "only allowed value for type is `unknown`" })
|
||||
type!: "unknown";
|
||||
|
||||
@IsString()
|
||||
location!: string;
|
||||
}
|
||||
|
||||
export type OutputLocation_2024_06_14 =
|
||||
| OutputAddressLocation_2024_06_14
|
||||
| OutputLinkLocation_2024_06_14
|
||||
| OutputIntegrationLocation_2024_06_14
|
||||
| OutputPhoneLocation_2024_06_14
|
||||
| OutputAttendeeAddressLocation_2024_06_14
|
||||
| OutputAttendeePhoneLocation_2024_06_14
|
||||
| OutputAttendeeDefinedLocation_2024_06_14
|
||||
| OutputConferencingLocation_2024_06_14
|
||||
| OutputUnknownLocation_2024_06_14;
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class OutputLocationValidator_2024_06_14 implements ValidatorConstraintInterface {
|
||||
private classTypeMap: { [key: string]: new () => OutputLocation_2024_06_14 } = {
|
||||
address: OutputAddressLocation_2024_06_14,
|
||||
link: OutputLinkLocation_2024_06_14,
|
||||
integration: OutputIntegrationLocation_2024_06_14,
|
||||
phone: OutputPhoneLocation_2024_06_14,
|
||||
attendeePhone: OutputAttendeePhoneLocation_2024_06_14,
|
||||
attendeeAddress: OutputAttendeeAddressLocation_2024_06_14,
|
||||
attendeeDefined: OutputAttendeeDefinedLocation_2024_06_14,
|
||||
conferencing: OutputConferencingLocation_2024_06_14,
|
||||
unknown: OutputUnknownLocation_2024_06_14,
|
||||
};
|
||||
|
||||
async validate(locations: { type: string }[]) {
|
||||
if (!Array.isArray(locations)) {
|
||||
throw new BadRequestException(`'locations' must be an array.`);
|
||||
}
|
||||
|
||||
if (!locations.length) {
|
||||
throw new BadRequestException(`'locations' must contain at least 1 location.`);
|
||||
}
|
||||
|
||||
for (const location of locations) {
|
||||
const { type } = location;
|
||||
if (!type) {
|
||||
throw new BadRequestException(`Each object in 'locations' must have a 'type' property.`);
|
||||
}
|
||||
|
||||
const ClassType = this.classTypeMap[type];
|
||||
if (!ClassType) {
|
||||
throw new BadRequestException(`Unsupported output type '${type}'.`);
|
||||
}
|
||||
|
||||
const instance = plainToInstance(ClassType, location);
|
||||
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 ${type} location: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
defaultMessage() {
|
||||
return `Validation failed for one or more location entries.`;
|
||||
}
|
||||
}
|
||||
|
||||
export function ValidateOutputLocations_2024_06_14(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 OutputLocationValidator_2024_06_14(),
|
||||
});
|
||||
};
|
||||
}
|
||||
+2
-2
@@ -7,7 +7,7 @@ import type {
|
||||
transformRecurrenceApiToInternal,
|
||||
transformSeatsApiToInternal,
|
||||
transformBookingFieldsApiToInternal,
|
||||
TransformedLocationsSchema,
|
||||
InternalLocationsSchema,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
import type { CreateEventTypeInput_2024_06_14, ConfirmationPolicyTransformedSchema } from "../inputs";
|
||||
@@ -32,7 +32,7 @@ export type InputEventTransformed_2024_06_14 = Omit<
|
||||
slug: string;
|
||||
eventName?: string;
|
||||
bookingLimits?: ReturnType<typeof transformIntervalLimitsApiToInternal>;
|
||||
locations?: z.infer<typeof TransformedLocationsSchema>;
|
||||
locations?: z.infer<typeof InternalLocationsSchema>;
|
||||
bookingFields?: ReturnType<typeof transformBookingFieldsApiToInternal>;
|
||||
durationLimits?: ReturnType<typeof transformIntervalLimitsApiToInternal>;
|
||||
recurringEvent?: ReturnType<typeof transformRecurrenceApiToInternal>;
|
||||
|
||||
Reference in new issue
Block a user