fix: v2 team metadata (#19939)

* refactor: allow metadata to also receive numbers and booleans

* refactor: Team metadata

* refactor: Managed orgs metadata

* refactor: Team metadata

* test: organizations teams create team with metadata

---------

Co-authored-by: Morgan <[email protected]>
This commit is contained in:
Lauris SkraucisandMorgan authored and GitHub committed 2025-03-11 15:03:30 +00:00
1 parent b7c5cfcf02
commit e6f561c3d7
12 files changed
+184 -61

No files matched your search

@@ -1,6 +1,12 @@
import type { ValidationOptions, ValidationArguments } from "class-validator";
import { registerDecorator } from "class-validator";
export const METADATA_DOCS = `You can store any additional data you want here.
Metadata must have at most 50 keys, each key up to 40 characters.
Values can be strings (up to 500 characters), numbers, or booleans.`;
export type Metadata = Record<string, string | number | boolean>;
export function ValidateMetadata(validationOptions?: ValidationOptions) {
return function (object: any, propertyName: string) {
registerDecorator({
@@ -41,21 +47,13 @@ export function ValidateMetadata(validationOptions?: ValidationOptions) {
}
function isInvalidValidKeyValue(keyValue: any) {
if (!isString(keyValue)) {
return true;
if (typeof keyValue === "number" || typeof keyValue === "boolean") {
return false;
}
if (isTooLong(keyValue)) {
return true;
if (typeof keyValue === "string") {
return keyValue.length > 500;
}
return false;
}
function isString(keyValue: any): keyValue is string {
return typeof keyValue === "string";
}
function isTooLong(keyValue: string) {
return keyValue.length > 500;
return true;
}
@@ -1,6 +1,8 @@
import { ApiProperty as DocsProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { Expose } from "class-transformer";
import { IsBoolean, IsInt, IsOptional, IsString, IsUrl, Length } from "class-validator";
import { Expose, Transform } from "class-transformer";
import { IsBoolean, IsInt, IsObject, IsOptional, IsString, IsUrl, Length } from "class-validator";
import type { Metadata } from "@calcom/platform-types/bookings/2024-08-13/inputs/validators/validate-metadata";
export class TeamOutputDto {
@IsInt()
@@ -79,11 +81,20 @@ export class TeamOutputDto {
@ApiPropertyOptional()
readonly hideBookATeamMember?: boolean = false;
@ApiPropertyOptional({
type: Object,
example: { key: "value" },
})
@IsObject()
@IsOptional()
@IsString()
@Expose()
@ApiPropertyOptional()
readonly metadata?: string;
@Transform(
// note(Lauris): added this transform because without it metadata is removed for some reason
({ obj }: { obj: { metadata: Metadata | null | undefined } }) => {
return obj.metadata || undefined;
}
)
metadata?: Metadata;
@IsOptional()
@IsString()