From 8784be067f1aa51ff0cd8079eba4e4530b16cde0 Mon Sep 17 00:00:00 2001 From: Rajiv Sahal Date: Mon, 9 Sep 2024 14:56:16 +0530 Subject: [PATCH] chore: fix input DTOs for v2 calendar busy times endpoint (#16526) * add class-transformer package to type * update input dtos for get busy times and fix type issue * fixup --------- Co-authored-by: Keith Williams --- packages/platform/types/calendars.ts | 23 +++++++++++++++++++++++ packages/platform/types/package.json | 1 + 2 files changed, 24 insertions(+) diff --git a/packages/platform/types/calendars.ts b/packages/platform/types/calendars.ts index 928f786271..0801c1ee22 100644 --- a/packages/platform/types/calendars.ts +++ b/packages/platform/types/calendars.ts @@ -1,9 +1,12 @@ +import { ApiProperty } from "@nestjs/swagger"; import { Type } from "class-transformer"; +import { Transform } from "class-transformer"; import { IsNumber, IsString, IsOptional, IsArray, ValidateNested, Validate } from "class-validator"; import { IsYearMonthDays } from "./validators/isYearMonthDays"; export class Calendar { + @Transform(({ value }: { value: string }) => value && parseInt(value)) @IsNumber() credentialId!: number; @@ -12,19 +15,39 @@ export class Calendar { } export class CalendarBusyTimesInput { + @ApiProperty({ + required: true, + description: "The timezone of the logged in user represented as a string", + example: "America/New_York", + }) @IsString() loggedInUsersTz!: string; + @ApiProperty({ + required: false, + description: "The starting date for the busy times query", + example: "2023-10-01", + }) @IsString() @IsOptional() @Validate(IsYearMonthDays) dateFrom?: string | null; + @ApiProperty({ + required: false, + description: "The ending date for the busy times query", + example: "2023-10-31", + }) @IsString() @IsOptional() @Validate(IsYearMonthDays) dateTo?: string | null; + @ApiProperty({ + required: true, + description: "An array of Calendar objects representing the calendars to be loaded", + example: `[{ credentialId: "1", externalId: "AQgtJE7RnHEeyisVq2ENs2gAAAgEGAAAACgtJE7RnHEeyisVq2ENs2gAAAhSDAAAA" }, { credentialId: "2", externalId: "AQM7RnHEeyisVq2ENs2gAAAhFDBBBBB" }]`, + }) @IsArray() @ValidateNested({ each: true }) @Type(() => Calendar) diff --git a/packages/platform/types/package.json b/packages/platform/types/package.json index 7228b41fee..80110c80ad 100644 --- a/packages/platform/types/package.json +++ b/packages/platform/types/package.json @@ -12,6 +12,7 @@ "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", "@types/express": "^4.17.21", + "class-transformer": "^0.5.1", "class-validator": "^0.14.0" } }