feat: add recurringEvent attribute to api/v2/event-types (#16251)
* feat: added recurringEvent attribute to api/v2/event-types * changed `recurringEvent` to `recurrence` * Update CHANGELOG.md * remove /dist/ import * change `as` to `satisfies` * testing some changes * Revert "testing some changes" This reverts commit 464d2611ed19dbd6ae390332b4d6dd5884bcae3b. * Update recurrence.input.ts * fix: apiv2 tsconfig enums * Update CHANGELOG.md * removed dev imports * Update package.json * Update api-request.spec.ts * Update api-request.spec.ts * added recurrence to update-event-type.input --------- Co-authored-by: Morgan Vernay <[email protected]>
This commit is contained in:
1 parent
03051a2bb1
commit
ef11755488
25 files changed
+512
-102
No files matched your search
@@ -15,7 +15,7 @@ export const substituteVariables = (
|
||||
|
||||
variables.forEach((variable) => {
|
||||
for (const key in response) {
|
||||
const field = fields.find((field) => field.id === key)
|
||||
const field = fields.find((field) => field.id === key);
|
||||
if (!field) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { FrequencyInput } from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
BookingField_2024_06_14,
|
||||
Location_2024_06_14,
|
||||
BookingLimitsCount_2024_06_14,
|
||||
BookingWindow_2024_06_14,
|
||||
Recurrence_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import type { UserField } from "./api-request";
|
||||
@@ -14,6 +16,7 @@ import {
|
||||
transformSelectOptions,
|
||||
transformApiEventTypeIntervalLimits,
|
||||
transformApiEventTypeFutureBookingLimits,
|
||||
transformApiEventTypeRecurrence,
|
||||
} from "./api-request";
|
||||
|
||||
describe("transformApiEventTypeLocations", () => {
|
||||
@@ -653,3 +656,21 @@ describe("transformApiEventTypeFutureBookingLimits", () => {
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformApiEventTypeRecurrence", () => {
|
||||
it("should transform recurrence", () => {
|
||||
const input: Recurrence_2024_06_14 = {
|
||||
frequency: FrequencyInput.weekly,
|
||||
interval: 2,
|
||||
occurrences: 10,
|
||||
};
|
||||
const expectedOutput = {
|
||||
interval: 2,
|
||||
count: 10,
|
||||
freq: 2,
|
||||
};
|
||||
const result = transformApiEventTypeRecurrence(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
BookingWindowPeriodInputTypeEnum_2024_06_14,
|
||||
BookingWindowPeriodOutputTypeEnum_2024_06_14,
|
||||
BookingLimitsEnum_2024_06_14,
|
||||
Frequency,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import {
|
||||
type CreateEventTypeInput_2024_06_14,
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
type TransformFutureBookingsLimitSchema_2024_06_14,
|
||||
type BookingLimitsKeyOutputType_2024_06_14,
|
||||
type TransformBookingLimitsSchema_2024_06_14,
|
||||
type TransformRecurringEventSchema_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
const integrationsMapping: Record<Integration_2024_06_14, string> = {
|
||||
@@ -123,7 +125,7 @@ function transformApiEventTypeIntervalLimits(
|
||||
Object.entries(inputBookingLimits).map(([key, value]) => {
|
||||
const outputKey: BookingLimitsKeyOutputType_2024_06_14 = BookingLimitsEnum_2024_06_14[
|
||||
key as keyof typeof BookingLimitsEnum_2024_06_14
|
||||
] as BookingLimitsKeyOutputType_2024_06_14;
|
||||
] satisfies BookingLimitsKeyOutputType_2024_06_14;
|
||||
res[outputKey] = value;
|
||||
});
|
||||
return res;
|
||||
@@ -160,6 +162,17 @@ function transformApiEventTypeFutureBookingLimits(
|
||||
}
|
||||
}
|
||||
|
||||
function transformApiEventTypeRecurrence(
|
||||
recurrence: CreateEventTypeInput_2024_06_14["recurrence"]
|
||||
): TransformRecurringEventSchema_2024_06_14 | undefined {
|
||||
if (!recurrence) return undefined;
|
||||
return {
|
||||
interval: recurrence.interval,
|
||||
count: recurrence.occurrences,
|
||||
freq: Frequency[recurrence.frequency as keyof typeof Frequency],
|
||||
} satisfies TransformRecurringEventSchema_2024_06_14;
|
||||
}
|
||||
|
||||
export function transformSelectOptions(options: string[]) {
|
||||
return options.map((option) => ({
|
||||
label: option,
|
||||
@@ -262,4 +275,5 @@ export {
|
||||
transformApiEventTypeBookingFields,
|
||||
transformApiEventTypeIntervalLimits,
|
||||
transformApiEventTypeFutureBookingLimits,
|
||||
transformApiEventTypeRecurrence,
|
||||
};
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
IntegrationLocation_2024_06_14,
|
||||
TransformBookingLimitsSchema_2024_06_14,
|
||||
TransformFutureBookingsLimitSchema_2024_06_14,
|
||||
TransformRecurringEventSchema_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import type { UserField } from "./api-request";
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
getResponseEventTypeBookingFields,
|
||||
getResponseEventTypeIntervalLimits,
|
||||
getResponseEventTypeFutureBookingLimits,
|
||||
getResponseEventTypeRecurrence,
|
||||
} from "./api-response";
|
||||
|
||||
describe("getResponseEventTypeLocations", () => {
|
||||
@@ -574,7 +576,7 @@ describe("getResponseEventTypeBookingFields", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformApiEventTypeIntervalLimits", () => {
|
||||
describe("getResponseEventTypeIntervalLimits", () => {
|
||||
it("should reverse transform booking limits count or booking limits duration", () => {
|
||||
const transformedField: TransformBookingLimitsSchema_2024_06_14 = {
|
||||
PER_DAY: 2,
|
||||
@@ -595,7 +597,7 @@ describe("transformApiEventTypeIntervalLimits", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformApiEventTypeFutureBookingLimits", () => {
|
||||
describe("getResponseEventTypeFutureBookingLimits", () => {
|
||||
it("should reverse transform range type", () => {
|
||||
const transformedField: TransformFutureBookingsLimitSchema_2024_06_14 = {
|
||||
periodType: "RANGE",
|
||||
@@ -679,3 +681,22 @@ describe("transformApiEventTypeFutureBookingLimits", () => {
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getResponseEventTypeRecurrence", () => {
|
||||
it("should reverse transform recurringEvent", () => {
|
||||
const transformedField: TransformRecurringEventSchema_2024_06_14 = {
|
||||
interval: 2,
|
||||
count: 10,
|
||||
freq: 2,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
frequency: "weekly",
|
||||
interval: 2,
|
||||
occurrences: 10,
|
||||
};
|
||||
const result = getResponseEventTypeRecurrence(transformedField);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,8 @@ import {
|
||||
BookingWindowPeriodInputTypeEnum_2024_06_14,
|
||||
BookingWindowPeriodOutputTypeEnum_2024_06_14,
|
||||
BookingLimitsEnum_2024_06_14,
|
||||
Frequency,
|
||||
FrequencyInput,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
AddressLocation_2024_06_14,
|
||||
@@ -17,6 +19,8 @@ import type {
|
||||
CalendarDaysWindow_2024_06_14,
|
||||
BusinessDaysWindow_2024_06_14,
|
||||
BookingField_2024_06_14,
|
||||
Recurrence_2024_06_14,
|
||||
TransformRecurringEventSchema_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import type { transformApiEventTypeBookingFields, transformApiEventTypeLocations } from "./api-request";
|
||||
@@ -255,9 +259,21 @@ function getResponseEventTypeFutureBookingLimits(
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function getResponseEventTypeRecurrence(
|
||||
transformRecurringEvent: TransformRecurringEventSchema_2024_06_14
|
||||
): Recurrence_2024_06_14 {
|
||||
return {
|
||||
interval: transformRecurringEvent.interval,
|
||||
occurrences: transformRecurringEvent.count,
|
||||
frequency: FrequencyInput[Frequency[transformRecurringEvent.freq] as keyof typeof FrequencyInput],
|
||||
} satisfies Recurrence_2024_06_14;
|
||||
}
|
||||
|
||||
export {
|
||||
getResponseEventTypeLocations,
|
||||
getResponseEventTypeBookingFields,
|
||||
getResponseEventTypeIntervalLimits,
|
||||
getResponseEventTypeFutureBookingLimits,
|
||||
getResponseEventTypeRecurrence,
|
||||
};
|
||||
@@ -1,9 +1,11 @@
|
||||
export enum Frequency {
|
||||
YEARLY = 0,
|
||||
MONTHLY = 1,
|
||||
WEEKLY = 2,
|
||||
DAILY = 3,
|
||||
HOURLY = 4,
|
||||
MINUTELY = 5,
|
||||
SECONDLY = 6,
|
||||
yearly = 0,
|
||||
monthly = 1,
|
||||
weekly = 2,
|
||||
}
|
||||
|
||||
export enum FrequencyInput {
|
||||
yearly = "yearly",
|
||||
monthly = "monthly",
|
||||
weekly = "weekly",
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
## 0.0.30
|
||||
• Feature: Added support for recurringEvent in api/v2/event-types.
|
||||
• Introduced the transformApiEventTypeRecurrence translator in packages/lib/event-types/transformers/api-request.ts. This enables the “recurringEvent” feature in the event-type API.
|
||||
• Added getResponseEventTypeRecurrence translator in packages/lib/event-types/transformers/api-response.ts to return data in a more human-friendly format.
|
||||
|
||||
## 0.0.28
|
||||
• Feature: Added support for new event-type limits in the API.
|
||||
• Introduced the transformApiEventTypeFutureBookingLimits translator in packages/lib/event-types/transformers/api-request.ts. This enables the “Limit future bookings” feature in the event-type API.
|
||||
|
||||
@@ -102,6 +102,8 @@ export {
|
||||
getResponseEventTypeIntervalLimits,
|
||||
getResponseEventTypeFutureBookingLimits,
|
||||
transformApiEventTypeFutureBookingLimits,
|
||||
transformApiEventTypeRecurrence,
|
||||
getResponseEventTypeRecurrence,
|
||||
} from "@calcom/lib/event-types/transformers";
|
||||
|
||||
export { parseBookingLimit } from "@calcom/lib";
|
||||
|
||||
+6
@@ -24,6 +24,7 @@ import type { BookingWindow_2024_06_14 } from "./booking-window.input";
|
||||
import { ValidateBookingWindow } from "./booking-window.input";
|
||||
import { ValidateLocations_2024_06_14 } from "./locations.input";
|
||||
import type { Location_2024_06_14 } from "./locations.input";
|
||||
import { Recurrence_2024_06_14 } from "./recurrence.input";
|
||||
|
||||
export const CREATE_EVENT_LENGTH_EXAMPLE = 60;
|
||||
export const CREATE_EVENT_TITLE_EXAMPLE = "Learn the secrets of masterchief!";
|
||||
@@ -103,6 +104,11 @@ export class CreateEventTypeInput_2024_06_14 {
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
offsetStart?: number;
|
||||
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => Recurrence_2024_06_14)
|
||||
recurrence?: Recurrence_2024_06_14;
|
||||
}
|
||||
|
||||
export enum HostPriority {
|
||||
|
||||
@@ -4,6 +4,6 @@ export * from "./booking-limits-count.input";
|
||||
export * from "./booking-window.input";
|
||||
export * from "./locations.input";
|
||||
export * from "./booking-fields.input";
|
||||
export * from "./recurring-event.input";
|
||||
export * from "./recurrence.input";
|
||||
export * from "./update-event-type.input";
|
||||
export * from "./get-event-types-query.input";
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsInt, IsEnum } from "class-validator";
|
||||
|
||||
import { FrequencyInput } from "@calcom/platform-enums";
|
||||
|
||||
export type TransformRecurringEventSchema_2024_06_14 = {
|
||||
interval: number;
|
||||
count: number;
|
||||
freq: number;
|
||||
};
|
||||
|
||||
export class Recurrence_2024_06_14 {
|
||||
@IsInt()
|
||||
@ApiProperty({ example: 10, description: "Repeats every {count} week | month | year" })
|
||||
interval!: number;
|
||||
|
||||
@IsInt()
|
||||
@ApiProperty({ example: 10, description: "Repeats for a maximum of {count} events" })
|
||||
occurrences!: number;
|
||||
|
||||
@IsEnum(FrequencyInput)
|
||||
@ApiProperty({ enum: FrequencyInput })
|
||||
frequency!: FrequencyInput;
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
import { IsInt, IsEnum, IsOptional, IsString, IsDateString } from "class-validator";
|
||||
|
||||
export enum Frequency {
|
||||
YEARLY = 0,
|
||||
MONTHLY = 1,
|
||||
WEEKLY = 2,
|
||||
DAILY = 3,
|
||||
HOURLY = 4,
|
||||
MINUTELY = 5,
|
||||
SECONDLY = 6,
|
||||
}
|
||||
|
||||
export class RecurringEvent_2024_06_14 {
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
dtstart?: Date;
|
||||
|
||||
@IsInt()
|
||||
interval!: number;
|
||||
|
||||
@IsInt()
|
||||
count!: number;
|
||||
|
||||
@IsEnum(Frequency)
|
||||
freq!: Frequency;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
until?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
tzid?: string;
|
||||
}
|
||||
+11
@@ -13,6 +13,7 @@ import { ValidateBookingWindow, type BookingWindow_2024_06_14 } from "./booking-
|
||||
import { Host } from "./create-event-type.input";
|
||||
import { ValidateLocations_2024_06_14 } from "./locations.input";
|
||||
import type { Location_2024_06_14 } from "./locations.input";
|
||||
import { Recurrence_2024_06_14 } from "./recurrence.input";
|
||||
|
||||
export class UpdateEventTypeInput_2024_06_14 {
|
||||
@IsOptional()
|
||||
@@ -87,6 +88,11 @@ export class UpdateEventTypeInput_2024_06_14 {
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
offsetStart?: number;
|
||||
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => Recurrence_2024_06_14)
|
||||
recurrence?: Recurrence_2024_06_14;
|
||||
}
|
||||
export class UpdateTeamEventTypeInput_2024_06_14 {
|
||||
@IsOptional()
|
||||
@@ -180,4 +186,9 @@ export class UpdateTeamEventTypeInput_2024_06_14 {
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
offsetStart?: number;
|
||||
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => Recurrence_2024_06_14)
|
||||
recurrence?: Recurrence_2024_06_14;
|
||||
}
|
||||
+5
-5
@@ -13,7 +13,7 @@ import {
|
||||
|
||||
import type { Location_2024_06_14, BookingField_2024_06_14, BookingWindow_2024_06_14 } from "../inputs";
|
||||
import { Host as TeamEventTypeHostInput, BookingLimitsDuration_2024_06_14 } from "../inputs";
|
||||
import { RecurringEvent_2024_06_14 } from "../inputs";
|
||||
import { Recurrence_2024_06_14 } from "../inputs";
|
||||
import { ValidateBookingFields_2024_06_14 } from "../inputs/booking-fields.input";
|
||||
import type { BookingLimitsCount_2024_06_14 } from "../inputs/booking-limits-count.input";
|
||||
import { ValidateLocations_2024_06_14 } from "../inputs/locations.input";
|
||||
@@ -101,8 +101,8 @@ export class EventTypeOutput_2024_06_14 {
|
||||
@IsEnum(SchedulingTypeEnum)
|
||||
schedulingType!: EventTypesOutputSchedulingType | null;
|
||||
|
||||
@Type(() => RecurringEvent_2024_06_14)
|
||||
recurringEvent!: RecurringEvent_2024_06_14 | null;
|
||||
@Type(() => Recurrence_2024_06_14)
|
||||
recurrence!: Recurrence_2024_06_14 | null;
|
||||
|
||||
@Type(() => Object)
|
||||
metadata!: Record<string, unknown>;
|
||||
@@ -211,8 +211,8 @@ export class TeamEventTypeOutput_2024_06_14 {
|
||||
@IsEnum(SchedulingTypeEnum)
|
||||
schedulingType!: EventTypesOutputSchedulingType | null;
|
||||
|
||||
@Type(() => RecurringEvent_2024_06_14)
|
||||
recurringEvent!: RecurringEvent_2024_06_14 | null;
|
||||
@Type(() => Recurrence_2024_06_14)
|
||||
recurrence!: Recurrence_2024_06_14 | null;
|
||||
|
||||
@Type(() => Object)
|
||||
metadata!: Record<string, unknown>;
|
||||
|
||||
Reference in new issue
Block a user