feat: add advanced tab attributes to api/v2/event-types (#16314)
* added bookerLayouts * added requiresConfirmation * added tests * undo extra changes * undo extra change * fixed imports * added requiresBookerEmailVerification * added hideCalendarNotes * added lockTimeZoneToggleOnBookingPage * added eventTypeColor * undo extra changes * added seats * added requiresConfirmationWillBlockSlot to requiresConfirmation * refactor: Implement BaseEventType class to avoid duplication across EventType input/output classes ## D-R-Y ## * temp-fix: will revert later * Correct placement of users array from EventTypeOutput to TeamEventTypeOutput * Refactor: Shifted transformation logic to controllers using interceptors and pipes for a cleaner service layer. * small fix * Refactor: Moved transformation logic from service to controller using interceptors and pipes ** organisations/event-types * feat: adde tests for `validateEventTypeInputs` * fix: failing test * fix: layout validator * renamed blockCalendarForUnconfirmedBookings to blockUnconfirmedBookingsInBooker * testing changes * added disabled state * fix merege conflict * renamed requiresConfirmation to confirmationPolicy * renamed OutputEventTypesResponseInterceptor to OutputTeamEventTypesResponseInterceptor * renamed `darkThemeColor` -> `darkThemeHex` and `lightThemeColor` -> `lightThemeHex` * renamed `eventTypeColor` -> `color` * changed `requiresConfirmation` -> `confirmationPolicy` * added tests for disabled state * added class-validators to `disabled?: false` * Revert: Split create and update input/output classes * feat: Refactor responses to use DTOs with plainToClass for explicit property control • Updated all endpoints to return response DTOs (e.g., CreateTeamEventTypeOutput, GetTeamEventTypeOutput) to ensure consistent Swagger documentation generation. • Introduced plainToClass for transforming responses, enabling explicit control over which properties are returned in the response, following Morgan’s recommendation. • Replaced generic HandlerResponse type with class-validator based DTOs for each endpoint, ensuring TypeScript enforces correct response structure. • Applied strategy: "excludeAll" to limit response properties to only those explicitly defined in the DTO, preventing unintended fields from being included in the API responses. * added pipes to transform output data * add clean script to platform-types package.json * added customName * added destination calendar * fixed type errors * added useDestinationCalendarEmail * refactor: api-reqest and api-response * Update event-type.output.ts * fixed errors * Update yarn.lock * added some missed properties to output * Update constants.ts * removed return type * fixed some type errors * reuse types * Improve readability of validation functions * Update CHANGELOG.md * chore: post publish platform libraries * Update documentation.json * fix: reset platform libraries to 0.0.0 * fixup! fix: reset platform libraries to 0.0.0 * Update event-type.tranformed.ts --------- Co-authored-by: supalarry <[email protected]> Co-authored-by: Morgan Vernay <[email protected]>
This commit is contained in:
68 files changed
+2859
-6305
No files matched your search
@@ -1,12 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { FrequencyInput } from "@calcom/platform-enums/monorepo";
|
||||
import {
|
||||
BookerLayoutsInputEnum_2024_06_14,
|
||||
BookerLayoutsOutputEnum_2024_06_14,
|
||||
ConfirmationPolicyEnum,
|
||||
NoticeThresholdUnitEnum,
|
||||
FrequencyInput,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
InputBookingField_2024_06_14,
|
||||
Location_2024_06_14,
|
||||
BookingLimitsCount_2024_06_14,
|
||||
BookingWindow_2024_06_14,
|
||||
BookerLayouts_2024_06_14,
|
||||
ConfirmationPolicy_2024_06_14,
|
||||
EventTypeColor_2024_06_14,
|
||||
Recurrence_2024_06_14,
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
SeatOptionsTransformedSchema,
|
||||
SeatOptionsDisabledSchema,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import type { CustomField } from "../internal-to-api/booking-fields";
|
||||
@@ -17,6 +29,10 @@ import {
|
||||
transformIntervalLimitsApiToInternal,
|
||||
transformFutureBookingLimitsApiToInternal,
|
||||
transformRecurrenceApiToInternal,
|
||||
transformSeatsApiToInternal,
|
||||
transformEventColorsApiToInternal,
|
||||
transformBookerLayoutsApiToInternal,
|
||||
transformConfirmationPolicyApiToInternal,
|
||||
} from "./index";
|
||||
|
||||
describe("transformLocationsApiToInternal", () => {
|
||||
@@ -585,6 +601,152 @@ describe("transformFutureBookingLimitsApiToInternal", () => {
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform disabled", () => {
|
||||
const input: BookingWindow_2024_06_14 = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
periodType: "UNLIMITED",
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformBookerLayoutsApiToInternal", () => {
|
||||
it("should transform booker layouts", () => {
|
||||
const input: BookerLayouts_2024_06_14 = {
|
||||
enabledLayouts: [
|
||||
BookerLayoutsInputEnum_2024_06_14.column,
|
||||
BookerLayoutsInputEnum_2024_06_14.month,
|
||||
BookerLayoutsInputEnum_2024_06_14.week,
|
||||
],
|
||||
defaultLayout: BookerLayoutsInputEnum_2024_06_14.week,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
enabledLayouts: [
|
||||
BookerLayoutsOutputEnum_2024_06_14.column_view,
|
||||
BookerLayoutsOutputEnum_2024_06_14.month_view,
|
||||
BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
],
|
||||
defaultLayout: BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
};
|
||||
const result = transformBookerLayoutsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformConfirmationPolicyApiToInternal", () => {
|
||||
it("should transform requires confirmation - time", () => {
|
||||
const input: ConfirmationPolicy_2024_06_14 = {
|
||||
type: ConfirmationPolicyEnum.TIME,
|
||||
noticeThreshold: {
|
||||
count: 60,
|
||||
unit: NoticeThresholdUnitEnum.MINUTES,
|
||||
},
|
||||
blockUnconfirmedBookingsInBooker: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationThreshold: {
|
||||
time: 60,
|
||||
unit: NoticeThresholdUnitEnum.MINUTES,
|
||||
},
|
||||
requiresConfirmationWillBlockSlot: true,
|
||||
};
|
||||
const result = transformConfirmationPolicyApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform requires confirmation - always", () => {
|
||||
const input: ConfirmationPolicy_2024_06_14 = {
|
||||
type: ConfirmationPolicyEnum.ALWAYS,
|
||||
blockUnconfirmedBookingsInBooker: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationWillBlockSlot: true,
|
||||
};
|
||||
const result = transformConfirmationPolicyApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform requires confirmation - disabled", () => {
|
||||
const input: ConfirmationPolicy_2024_06_14 = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
requiresConfirmation: false,
|
||||
requiresConfirmationWillBlockSlot: false,
|
||||
requiresConfirmationThreshold: undefined,
|
||||
};
|
||||
const result = transformConfirmationPolicyApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformEventColorsApiToInternal", () => {
|
||||
it("should transform event type colors", () => {
|
||||
const input: EventTypeColor_2024_06_14 = {
|
||||
darkThemeHex: "#292929",
|
||||
lightThemeHex: "#fafafa",
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
darkEventTypeColor: "#292929",
|
||||
lightEventTypeColor: "#fafafa",
|
||||
};
|
||||
|
||||
const result = transformEventColorsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformSeatsApiToInternal", () => {
|
||||
it("should transform seat options", () => {
|
||||
const input: CreateEventTypeInput_2024_06_14["seats"] = {
|
||||
seatsPerTimeSlot: 20,
|
||||
showAttendeeInfo: true,
|
||||
showAvailabilityCount: false,
|
||||
};
|
||||
|
||||
const expectedOutput: SeatOptionsTransformedSchema = {
|
||||
seatsPerTimeSlot: 20,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: false,
|
||||
};
|
||||
|
||||
const result = transformSeatsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform seat options - disabled", () => {
|
||||
const input: CreateEventTypeInput_2024_06_14["seats"] = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const expectedOutput: SeatOptionsDisabledSchema = {
|
||||
seatsPerTimeSlot: null,
|
||||
};
|
||||
|
||||
const result = transformSeatsApiToInternal(input);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformRecurrenceApiToInternal", () => {
|
||||
@@ -600,7 +762,15 @@ describe("transformRecurrenceApiToInternal", () => {
|
||||
freq: 2,
|
||||
};
|
||||
const result = transformRecurrenceApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform recurrence - disabled", () => {
|
||||
const input: CreateEventTypeInput_2024_06_14["recurrence"] = {
|
||||
disabled: true,
|
||||
};
|
||||
const expectedOutput = undefined;
|
||||
const result = transformRecurrenceApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
BookerLayoutsInputEnum_2024_06_14,
|
||||
BookerLayoutsOutputEnum_2024_06_14,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import { type CreateEventTypeInput_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformBookerLayoutsApiToInternal(
|
||||
inputBookerLayout: CreateEventTypeInput_2024_06_14["bookerLayouts"]
|
||||
) {
|
||||
if (!inputBookerLayout) return undefined;
|
||||
|
||||
const inputToOutputMap = {
|
||||
[BookerLayoutsInputEnum_2024_06_14.month]: BookerLayoutsOutputEnum_2024_06_14.month_view,
|
||||
[BookerLayoutsInputEnum_2024_06_14.week]: BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
[BookerLayoutsInputEnum_2024_06_14.column]: BookerLayoutsOutputEnum_2024_06_14.column_view,
|
||||
};
|
||||
|
||||
return {
|
||||
defaultLayout: inputToOutputMap[inputBookerLayout.defaultLayout],
|
||||
enabledLayouts: inputBookerLayout.enabledLayouts.map((layout) => inputToOutputMap[layout]),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { ConfirmationPolicyEnum } from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
ConfirmationPolicyTransformedSchema,
|
||||
NoticeThresholdTransformedSchema,
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformConfirmationPolicyApiToInternal(
|
||||
inputConfirmationPolicy: CreateEventTypeInput_2024_06_14["confirmationPolicy"]
|
||||
): ConfirmationPolicyTransformedSchema | undefined {
|
||||
if (!inputConfirmationPolicy) return undefined;
|
||||
if (inputConfirmationPolicy.disabled) {
|
||||
return {
|
||||
requiresConfirmation: false,
|
||||
requiresConfirmationWillBlockSlot: false,
|
||||
requiresConfirmationThreshold: undefined,
|
||||
};
|
||||
}
|
||||
switch (inputConfirmationPolicy.type) {
|
||||
case ConfirmationPolicyEnum.ALWAYS:
|
||||
return {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationThreshold: undefined,
|
||||
requiresConfirmationWillBlockSlot: inputConfirmationPolicy.blockUnconfirmedBookingsInBooker,
|
||||
};
|
||||
case ConfirmationPolicyEnum.TIME:
|
||||
return {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationThreshold: {
|
||||
unit: inputConfirmationPolicy.noticeThreshold?.unit,
|
||||
time: inputConfirmationPolicy.noticeThreshold?.count,
|
||||
} as NoticeThresholdTransformedSchema,
|
||||
requiresConfirmationWillBlockSlot: inputConfirmationPolicy.blockUnconfirmedBookingsInBooker,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type {
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
EventTypeColorsTransformedSchema,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformEventColorsApiToInternal(
|
||||
inputEventTypeColors: CreateEventTypeInput_2024_06_14["color"]
|
||||
): EventTypeColorsTransformedSchema | undefined {
|
||||
if (!inputEventTypeColors) return undefined;
|
||||
|
||||
return {
|
||||
darkEventTypeColor: inputEventTypeColors.darkThemeHex,
|
||||
lightEventTypeColor: inputEventTypeColors.lightThemeHex,
|
||||
};
|
||||
}
|
||||
@@ -12,6 +12,14 @@ import {
|
||||
export function transformFutureBookingLimitsApiToInternal(
|
||||
inputBookingLimits: CreateEventTypeInput_2024_06_14["bookingWindow"]
|
||||
): TransformFutureBookingsLimitSchema_2024_06_14 | undefined {
|
||||
if (!inputBookingLimits) {
|
||||
return;
|
||||
}
|
||||
if (inputBookingLimits.disabled) {
|
||||
return {
|
||||
periodType: BookingWindowPeriodOutputTypeEnum_2024_06_14.UNLIMITED,
|
||||
};
|
||||
}
|
||||
switch (inputBookingLimits?.type) {
|
||||
case BookingWindowPeriodInputTypeEnum_2024_06_14.businessDays:
|
||||
return {
|
||||
|
||||
@@ -3,3 +3,7 @@ export * from "./locations";
|
||||
export * from "./recurrence";
|
||||
export * from "./interval-limits";
|
||||
export * from "./future-booking-limits";
|
||||
export * from "./booker-layouts";
|
||||
export * from "./confirmation-policy";
|
||||
export * from "./event-colors";
|
||||
export * from "./seats";
|
||||
@@ -9,6 +9,9 @@ export function transformIntervalLimitsApiToInternal(
|
||||
inputBookingLimits: CreateEventTypeInput_2024_06_14["bookingLimitsCount"]
|
||||
) {
|
||||
const res: TransformBookingLimitsSchema_2024_06_14 = {};
|
||||
if (inputBookingLimits?.disabled) {
|
||||
return res;
|
||||
}
|
||||
inputBookingLimits &&
|
||||
Object.entries(inputBookingLimits).map(([key, value]) => {
|
||||
const outputKey: BookingLimitsKeyOutputType_2024_06_14 = BookingLimitsEnum_2024_06_14[
|
||||
|
||||
@@ -71,7 +71,7 @@ const UserPhoneSchema = z.object({
|
||||
|
||||
type InPersonLocation = z.infer<typeof InPersonSchema>;
|
||||
type LinkLocation = z.infer<typeof LinkSchema>;
|
||||
type IntegrationLocation = z.infer<typeof IntegrationSchema>;
|
||||
export type IntegrationLocation = z.infer<typeof IntegrationSchema>;
|
||||
type UserPhoneLocation = z.infer<typeof UserPhoneSchema>;
|
||||
|
||||
const TransformedLocationSchema = z.union([InPersonSchema, LinkSchema, IntegrationSchema, UserPhoneSchema]);
|
||||
|
||||
@@ -7,7 +7,8 @@ import {
|
||||
export function transformRecurrenceApiToInternal(
|
||||
recurrence: CreateEventTypeInput_2024_06_14["recurrence"]
|
||||
): TransformRecurringEventSchema_2024_06_14 | undefined {
|
||||
if (!recurrence) return undefined;
|
||||
if (!recurrence || recurrence.disabled) return undefined;
|
||||
|
||||
return {
|
||||
interval: recurrence.interval,
|
||||
count: recurrence.occurrences,
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import type {
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
SeatOptionsTransformedSchema,
|
||||
SeatOptionsDisabledSchema,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformSeatsApiToInternal(
|
||||
inputSeats: CreateEventTypeInput_2024_06_14["seats"]
|
||||
): SeatOptionsTransformedSchema | SeatOptionsDisabledSchema | undefined {
|
||||
if (!inputSeats) return undefined;
|
||||
|
||||
if (inputSeats.disabled)
|
||||
return {
|
||||
seatsPerTimeSlot: null,
|
||||
};
|
||||
|
||||
return {
|
||||
seatsPerTimeSlot: inputSeats.seatsPerTimeSlot,
|
||||
seatsShowAttendees: inputSeats.showAttendeeInfo,
|
||||
seatsShowAvailabilityCount: inputSeats.showAvailabilityCount,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
BookerLayoutsInputEnum_2024_06_14,
|
||||
BookerLayoutsOutputEnum_2024_06_14,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import type { BookerLayoutsTransformedSchema } from "@calcom/platform-types";
|
||||
|
||||
export function transformBookerLayoutsInternalToApi(
|
||||
transformedBookerLayouts: BookerLayoutsTransformedSchema
|
||||
) {
|
||||
const outputToInputMap = {
|
||||
[BookerLayoutsOutputEnum_2024_06_14.month_view]: BookerLayoutsInputEnum_2024_06_14.month,
|
||||
[BookerLayoutsOutputEnum_2024_06_14.week_view]: BookerLayoutsInputEnum_2024_06_14.week,
|
||||
[BookerLayoutsOutputEnum_2024_06_14.column_view]: BookerLayoutsInputEnum_2024_06_14.column,
|
||||
};
|
||||
|
||||
return {
|
||||
defaultLayout: outputToInputMap[transformedBookerLayouts.defaultLayout],
|
||||
enabledLayouts: transformedBookerLayouts.enabledLayouts.map((layout) => outputToInputMap[layout]),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { EventTypeColorsTransformedSchema, EventTypeColor_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformEventTypeColorsInternalToApi(
|
||||
transformedColors: EventTypeColorsTransformedSchema
|
||||
): EventTypeColor_2024_06_14 {
|
||||
return {
|
||||
darkThemeHex: transformedColors.darkEventTypeColor,
|
||||
lightThemeHex: transformedColors.lightEventTypeColor,
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
RangeWindow_2024_06_14,
|
||||
CalendarDaysWindow_2024_06_14,
|
||||
BusinessDaysWindow_2024_06_14,
|
||||
Disabled_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformFutureBookingLimitsInternalToApi(
|
||||
@@ -38,6 +39,11 @@ export function transformFutureBookingLimitsInternalToApi(
|
||||
value: transformedFutureBookingsLimitsFields.periodDays,
|
||||
rolling: false,
|
||||
} as CalendarDaysWindow_2024_06_14 | BusinessDaysWindow_2024_06_14;
|
||||
|
||||
case BookingWindowPeriodOutputTypeEnum_2024_06_14.UNLIMITED:
|
||||
return {
|
||||
disabled: true,
|
||||
} as Disabled_2024_06_14;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -3,3 +3,7 @@ export * from "./locations";
|
||||
export * from "./recurrence";
|
||||
export * from "./interval-limits";
|
||||
export * from "./future-booking-limits";
|
||||
export * from "./booker-layouts";
|
||||
export * from "./event-type-colors";
|
||||
export * from "./requires-confirmation";
|
||||
export * from "./seats";
|
||||
@@ -1,5 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
BookerLayoutsInputEnum_2024_06_14,
|
||||
BookerLayoutsOutputEnum_2024_06_14,
|
||||
ConfirmationPolicyEnum,
|
||||
NoticeThresholdUnitEnum,
|
||||
} from "@calcom/platform-enums/monorepo";
|
||||
import type {
|
||||
AddressLocation_2024_06_14,
|
||||
LinkLocation_2024_06_14,
|
||||
@@ -7,7 +13,11 @@ import type {
|
||||
IntegrationLocation_2024_06_14,
|
||||
TransformBookingLimitsSchema_2024_06_14,
|
||||
TransformFutureBookingsLimitSchema_2024_06_14,
|
||||
BookerLayoutsTransformedSchema,
|
||||
EventTypeColorsTransformedSchema,
|
||||
TransformRecurringEventSchema_2024_06_14,
|
||||
SeatOptionsTransformedSchema,
|
||||
SeatOptionsDisabledSchema,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
import {
|
||||
@@ -16,6 +26,10 @@ import {
|
||||
transformIntervalLimitsInternalToApi,
|
||||
transformFutureBookingLimitsInternalToApi,
|
||||
transformRecurrenceInternalToApi,
|
||||
transformBookerLayoutsInternalToApi,
|
||||
transformRequiresConfirmationInternalToApi,
|
||||
transformEventTypeColorsInternalToApi,
|
||||
transformSeatsInternalToApi,
|
||||
} from ".";
|
||||
import type { CustomField } from "./booking-fields";
|
||||
|
||||
@@ -621,6 +635,162 @@ describe("transformFutureBookingLimitsInternalToApi", () => {
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should reverse transform disabled", () => {
|
||||
const transformedField: TransformFutureBookingsLimitSchema_2024_06_14 = {
|
||||
periodType: "UNLIMITED",
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const result = transformFutureBookingLimitsInternalToApi(transformedField);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformBookerLayoutsInternalToApi", () => {
|
||||
it("should reverse transform booker layout", () => {
|
||||
const transformedField: BookerLayoutsTransformedSchema = {
|
||||
enabledLayouts: [
|
||||
BookerLayoutsOutputEnum_2024_06_14.column_view,
|
||||
BookerLayoutsOutputEnum_2024_06_14.month_view,
|
||||
BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
],
|
||||
defaultLayout: BookerLayoutsOutputEnum_2024_06_14.week_view,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
enabledLayouts: [
|
||||
BookerLayoutsInputEnum_2024_06_14.column,
|
||||
BookerLayoutsInputEnum_2024_06_14.month,
|
||||
BookerLayoutsInputEnum_2024_06_14.week,
|
||||
],
|
||||
defaultLayout: BookerLayoutsInputEnum_2024_06_14.week,
|
||||
};
|
||||
const result = transformBookerLayoutsInternalToApi(transformedField);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformRequiresConfirmationInternalToApi", () => {
|
||||
it("should reverse transform requires confirmation - time", () => {
|
||||
const transformedField = {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationThreshold: {
|
||||
time: 60,
|
||||
unit: NoticeThresholdUnitEnum.MINUTES,
|
||||
},
|
||||
requiresConfirmationWillBlockSlot: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
type: ConfirmationPolicyEnum.TIME,
|
||||
noticeThreshold: {
|
||||
count: 60,
|
||||
unit: NoticeThresholdUnitEnum.MINUTES,
|
||||
},
|
||||
blockUnconfirmedBookingsInBooker: true,
|
||||
};
|
||||
const result = transformRequiresConfirmationInternalToApi(
|
||||
transformedField.requiresConfirmation,
|
||||
transformedField.requiresConfirmationWillBlockSlot,
|
||||
transformedField.requiresConfirmationThreshold
|
||||
);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should reverse transform requires confirmation - always", () => {
|
||||
const transformedField = {
|
||||
requiresConfirmation: true,
|
||||
requiresConfirmationWillBlockSlot: true,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
type: ConfirmationPolicyEnum.ALWAYS,
|
||||
blockUnconfirmedBookingsInBooker: true,
|
||||
};
|
||||
const result = transformRequiresConfirmationInternalToApi(
|
||||
transformedField.requiresConfirmation,
|
||||
transformedField.requiresConfirmationWillBlockSlot,
|
||||
undefined
|
||||
);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should reverse transform requires confirmation - disabled", () => {
|
||||
const transformedField = {
|
||||
requiresConfirmation: false,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
disabled: true,
|
||||
};
|
||||
const result = transformRequiresConfirmationInternalToApi(
|
||||
transformedField.requiresConfirmation,
|
||||
!!undefined,
|
||||
undefined
|
||||
);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformEventTypeColorsInternalToApi", () => {
|
||||
it("should reverse transform event type colors", () => {
|
||||
const transformedField: EventTypeColorsTransformedSchema = {
|
||||
darkEventTypeColor: "#292929",
|
||||
lightEventTypeColor: "#fafafa",
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
darkThemeHex: "#292929",
|
||||
lightThemeHex: "#fafafa",
|
||||
};
|
||||
|
||||
const result = transformEventTypeColorsInternalToApi(transformedField);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformSeatsInternalToApi", () => {
|
||||
it("should reverse transform event type seats", () => {
|
||||
const transformedSeats: SeatOptionsTransformedSchema = {
|
||||
seatsPerTimeSlot: 10,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: false,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
seatsPerTimeSlot: 10,
|
||||
showAttendeeInfo: true,
|
||||
showAvailabilityCount: false,
|
||||
};
|
||||
|
||||
const result = transformSeatsInternalToApi(transformedSeats);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should reverse transform event type seats - disabled", () => {
|
||||
const transformedSeats: SeatOptionsDisabledSchema = {
|
||||
seatsPerTimeSlot: null,
|
||||
};
|
||||
|
||||
const expectedOutput = {
|
||||
disabled: true,
|
||||
};
|
||||
|
||||
const result = transformSeatsInternalToApi(transformedSeats);
|
||||
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transformRecurrenceInternalToApi", () => {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { ConfirmationPolicyEnum } from "@calcom/platform-enums/monorepo";
|
||||
import type { NoticeThresholdTransformedSchema, ConfirmationPolicy_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformRequiresConfirmationInternalToApi(
|
||||
requiresConfirmation: boolean,
|
||||
requiresConfirmationWillBlockSlot: boolean,
|
||||
requiresConfirmationThreshold?: NoticeThresholdTransformedSchema
|
||||
): ConfirmationPolicy_2024_06_14 | undefined {
|
||||
if (requiresConfirmationThreshold?.unit) {
|
||||
return {
|
||||
type: ConfirmationPolicyEnum.TIME,
|
||||
noticeThreshold: {
|
||||
unit: requiresConfirmationThreshold.unit,
|
||||
count: requiresConfirmationThreshold.time,
|
||||
},
|
||||
blockUnconfirmedBookingsInBooker: requiresConfirmationWillBlockSlot,
|
||||
};
|
||||
} else if (requiresConfirmation) {
|
||||
return {
|
||||
type: ConfirmationPolicyEnum.ALWAYS,
|
||||
blockUnconfirmedBookingsInBooker: requiresConfirmationWillBlockSlot,
|
||||
};
|
||||
} else if (!requiresConfirmation) {
|
||||
return {
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type {
|
||||
SeatOptionsTransformedSchema,
|
||||
SeatOptionsDisabledSchema,
|
||||
CreateEventTypeInput_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
|
||||
export function transformSeatsInternalToApi(
|
||||
transformedSeats: SeatOptionsTransformedSchema | SeatOptionsDisabledSchema
|
||||
): CreateEventTypeInput_2024_06_14["seats"] {
|
||||
if (transformedSeats.seatsPerTimeSlot == null) {
|
||||
return {
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
seatsPerTimeSlot: transformedSeats.seatsPerTimeSlot,
|
||||
showAttendeeInfo: transformedSeats.seatsShowAttendees,
|
||||
showAvailabilityCount: transformedSeats.seatsShowAvailabilityCount,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user