fix: v2 Sentry errors (#20788)

* fix: Only Team Event Types are supported for Instant Meeting

* refactor: Cannot read properties of undefined (reading 'timeZone')

* fix: Cannot read properties of undefined (reading 'map')

* refactor: rearrange function order

* refactor: booking_seats_full_error

* fix: invalid_round_robin_host

* refactor: booking_time_out_of_bounds_error

* refactor: Attempting to book a meeting in the past.

* fix: obj.phoneNumber.trim is not a function

* fix: Cannot use 'in' operator to search for 'disabled' in 1
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2025-04-21 12:12:46 +03:00
1 parent 930165b6e8
commit f6c7d8d97f
9 files changed
+256 -183

No files matched your search

@@ -40,6 +40,7 @@ export const FAILED_EVENT_TYPE_IDENTIFICATION_ERROR_MESSAGE =
"Either eventTypeId or eventTypeSlug + username or eventTypeSlug + teamSlug must be provided";
function RequireEventTypeIdentification(validationOptions?: ValidationOptions) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return function (object: any) {
registerDecorator({
name: "requireEventTypeIdentification",
@@ -48,7 +49,7 @@ function RequireEventTypeIdentification(validationOptions?: ValidationOptions) {
options: validationOptions,
constraints: [],
validator: {
validate(_value: any, args: ValidationArguments) {
validate(_: unknown, args: ValidationArguments) {
const obj = args.object as CreateBookingInput_2024_08_13;
const hasEventTypeId = !!obj?.eventTypeId;
@@ -68,28 +69,31 @@ function RequireEventTypeIdentification(validationOptions?: ValidationOptions) {
}
function RequireEmailOrPhone(validationOptions?: ValidationOptions) {
return function (target: object, propertyName: string) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return function (object: any) {
registerDecorator({
name: "requireEmailOrPhone",
target: target.constructor,
propertyName: propertyName,
target: object,
propertyName: "attendee email or phone",
options: validationOptions,
constraints: [],
validator: {
validate(value: any, args: ValidationArguments) {
validate(_: unknown, args: ValidationArguments) {
const obj = args.object as Attendee;
const hasPhoneNumber = !!obj.phoneNumber && obj.phoneNumber.trim().length > 0;
const hasEmail = !!obj.email && obj.email.trim().length > 0;
const hasPhoneNumber = !!obj.phoneNumber;
const hasEmail = !!obj.email;
return hasPhoneNumber || hasEmail;
},
defaultMessage(): string {
return "At least one contact method (email or phone number) must be provided";
return "Attendee must have at least one contact method (email or phone number)";
},
},
});
};
}
@RequireEmailOrPhone()
class Attendee {
@ApiProperty({
type: String,
@@ -108,7 +112,6 @@ class Attendee {
@Validate((value: string) => !value || isEmail(value), {
message: "Invalid email format",
})
@RequireEmailOrPhone()
email?: string;
@ApiProperty({
@@ -162,15 +165,24 @@ export class CreateBookingInput_2024_08_13 {
@IsDateString()
start!: string;
@IsOptional()
@IsInt()
@Min(1)
@ApiPropertyOptional({
example: 30,
description: `If it is an event type that has multiple possible lengths that attendee can pick from, you can pass the desired booking length here.
If not provided then event type default length will be used for the booking.`,
@ApiProperty({
type: Attendee,
description: "The attendee's details.",
})
lengthInMinutes?: number;
@ValidateNested()
@Type(() => Attendee)
attendee!: Attendee;
@ApiPropertyOptional({
type: Object,
description:
"Booking field responses consisting of an object with booking field slug as keys and user response as values for custom booking fields added by you.",
example: { customField: "customValue" },
required: false,
})
@IsObject()
@IsOptional()
bookingFieldsResponses?: Record<string, unknown>;
@ApiPropertyOptional({
type: Number,
@@ -222,14 +234,6 @@ export class CreateBookingInput_2024_08_13 {
@IsString()
organizationSlug?: string;
@ApiProperty({
type: Attendee,
description: "The attendee's details.",
})
@ValidateNested()
@Type(() => Attendee)
attendee!: Attendee;
@ApiPropertyOptional({
type: [String],
description: "An optional list of guest emails attending the event.",
@@ -287,16 +291,15 @@ export class CreateBookingInput_2024_08_13 {
})
metadata?: Record<string, string>;
@ApiPropertyOptional({
type: Object,
description:
"Booking field responses consisting of an object with booking field slug as keys and user response as values.",
example: { customField: "customValue" },
required: false,
})
@IsObject()
@IsOptional()
bookingFieldsResponses?: Record<string, unknown>;
@IsInt()
@Min(1)
@ApiPropertyOptional({
example: 30,
description: `If it is an event type that has multiple possible lengths that attendee can pick from, you can pass the desired booking length here.
If not provided then event type default length will be used for the booking.`,
})
lengthInMinutes?: number;
}
export class CreateInstantBookingInput_2024_08_13 extends CreateBookingInput_2024_08_13 {
@@ -1,5 +1,5 @@
import { ApiProperty } from "@nestjs/swagger";
import type { ValidatorConstraintInterface, ValidationOptions } from "class-validator";
import type { ValidatorConstraintInterface, ValidationOptions, ValidationArguments } from "class-validator";
import { IsEnum, ValidatorConstraint, registerDecorator } from "class-validator";
import {
@@ -44,14 +44,49 @@ function IsValidLayout(validationOptions?: ValidationOptions) {
};
}
@ValidatorConstraint({ name: "isDefaultLayoutWithinEnabledLayouts", async: false })
export class DefaultLayoutEnabledValidator implements ValidatorConstraintInterface {
validate(_: unknown, args: ValidationArguments) {
const object = args.object as BookerLayouts_2024_06_14;
if (object.defaultLayout && Array.isArray(object.enabledLayouts) && object.enabledLayouts.length > 0) {
return object.enabledLayouts.includes(object.defaultLayout);
}
return false;
}
defaultMessage() {
return "If you pass the optional 'bookerLayouts' property, you must provide both 'bookerLayouts.defaultLayout' and 'bookerLayouts.enabledLayouts' and 'bookerLayouts.enabledLayouts' must include 'bookerLayouts.defaultLayout'";
}
}
function IsDefaultLayoutWithinEnabledLayouts(validationOptions?: ValidationOptions) {
return function (object: any) {
registerDecorator({
name: "isDefaultLayoutWithinEnabledLayouts",
target: object,
propertyName: "defaultLayout",
options: validationOptions,
constraints: [],
validator: DefaultLayoutEnabledValidator,
});
};
}
@IsDefaultLayoutWithinEnabledLayouts()
export class BookerLayouts_2024_06_14 {
@IsValidLayout({ message: "defaultLayout must be one of the valid layouts - month, week or column" })
@ApiProperty({ type: String, enum: BookerLayoutsInputEnum_2024_06_14 })
@IsEnum(BookerLayoutsInputEnum_2024_06_14)
defaultLayout!: BookerLayoutsInputEnum_2024_06_14;
@IsValidLayout({ message: "enabledLayouts must be one of the valid layouts." })
@ApiProperty({ type: [String], enum: BookerLayoutsInputEnum_2024_06_14 })
@IsValidLayout({
message: "enabledLayouts must be an array containing valid layouts - month, week or column",
})
@ApiProperty({
type: [String],
enum: BookerLayoutsInputEnum_2024_06_14,
description: "Array of valid layouts - month, week or column",
})
@IsEnum(BookerLayoutsInputEnum_2024_06_14, {
each: true,
message: "enabledLayouts must contain only valid layouts - month, week or column",
@@ -63,7 +63,7 @@ class BookingLimitsCountValidator implements ValidatorConstraintInterface {
} = {};
validate(value: BookingLimitsCount_2024_06_14) {
if (!value) return false;
if (!value || typeof value !== "object") return false;
if ("disabled" in value) {
return true;
}
@@ -97,9 +97,9 @@ class BookingLimitsCountValidator implements ValidatorConstraintInterface {
defaultMessage() {
const { invalidLimit, comparedLimit } = this.errorDetails;
if (invalidLimit && comparedLimit) {
return `Invalid booking limits: The number of bookings for ${invalidLimit} cannot exceed the number of bookings for ${comparedLimit}.`;
return `Invalid bookingLimitsCount: The number of bookings for ${invalidLimit} cannot exceed the number of bookings for ${comparedLimit}.`;
}
return `Invalid booking limits count structure`;
return `Invalid bookingLimitsCount`;
}
}
@@ -54,7 +54,7 @@ class BookingLimitsDurationValidator implements ValidatorConstraintInterface {
comparedLimit?: string;
} = {};
validate(value: BookingLimitsDuration_2024_06_14) {
if (!value) return false;
if (!value || typeof value !== "object") return false;
if ("disabled" in value) {
return true;
}
@@ -88,9 +88,9 @@ class BookingLimitsDurationValidator implements ValidatorConstraintInterface {
defaultMessage() {
const { invalidLimit, comparedLimit } = this.errorDetails;
if (invalidLimit && comparedLimit) {
return `Invalid booking durations: The duration of bookings for ${invalidLimit} cannot exceed the duration of bookings for ${comparedLimit}.`;
return `Invalid bookingLimitsDuration: The duration of bookings for ${invalidLimit} cannot exceed the duration of bookings for ${comparedLimit}.`;
}
return `Invalid booking durations structure`;
return `Invalid bookingLimitsDuration`;
}
}
@@ -288,6 +288,7 @@ class BaseCreateEventTypeInput {
"Should booker have week, month or column view. Specify default layout and enabled layouts user can pick.",
})
@Type(() => BookerLayouts_2024_06_14)
@ValidateNested()
bookerLayouts?: BookerLayouts_2024_06_14;
@IsOptional()
@@ -285,6 +285,7 @@ class BaseUpdateEventTypeInput {
"Should booker have week, month or column view. Specify default layout and enabled layouts user can pick.",
})
@Type(() => BookerLayouts_2024_06_14)
@ValidateNested()
bookerLayouts?: BookerLayouts_2024_06_14;
@IsOptional()