feat: v2 expose booking metadata (#17708)
* feat: accept metadata and store it in database * feat: accept metadata and store it in database * feat: add BookingSeat.metadata column * feat: handleNewBooking: store booking seat metadata when first time seated booking * feat: handleSeats, createNewSeat store metadata when 2nd+ seated booking * feat: return booking metadata in output * tests: metadata * test: seated bookings * swagger * fix: reassign bookings test * test: use different metadata in recurring * fix: test * test invalid metadata * refactor: output service * readd new line * chore: bump platform libraries * refactor: metadata doc
This commit is contained in:
1 parent
1404581f78
commit
58cac84f4a
21 files changed
+6158
-120
No files matched your search
@@ -9,6 +9,7 @@ import AttendeeCancelledEmail from "@calcom/emails/templates/attendee-cancelled-
|
||||
import AttendeeDeclinedEmail from "@calcom/emails/templates/attendee-declined-email";
|
||||
import AttendeeScheduledEmail from "@calcom/emails/templates/attendee-scheduled-email";
|
||||
import OrganizerCancelledEmail from "@calcom/emails/templates/organizer-cancelled-email";
|
||||
import OrganizerReassignedEmail from "@calcom/emails/templates/organizer-reassigned-email";
|
||||
import OrganizerScheduledEmail from "@calcom/emails/templates/organizer-scheduled-email";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import getBookingInfo from "@calcom/features/bookings/lib/getBookingInfo";
|
||||
@@ -109,7 +110,7 @@ export { handleCancelBooking };
|
||||
|
||||
export { eventTypeBookingFields, eventTypeLocations } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export { EventTypeMetaDataSchema, userMetadata } from "@calcom/prisma/zod-utils";
|
||||
export { EventTypeMetaDataSchema, userMetadata, bookingMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export {
|
||||
// note(Lauris): Api to internal
|
||||
@@ -200,3 +201,5 @@ export { AttendeeDeclinedEmail };
|
||||
export { AttendeeCancelledEmail };
|
||||
|
||||
export { OrganizerCancelledEmail };
|
||||
|
||||
export { OrganizerReassignedEmail };
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
|
||||
import type { BookingLanguageType } from "./language";
|
||||
import { BookingLanguage } from "./language";
|
||||
import { ValidateMetadata } from "./validators/validate-metadata";
|
||||
|
||||
class Attendee {
|
||||
@ApiProperty({
|
||||
@@ -122,16 +123,20 @@ export class CreateBookingInput_2024_08_13 {
|
||||
@IsOptional()
|
||||
location?: string;
|
||||
|
||||
// todo(Lauris): expose after refactoring metadata https://app.campsite.co/cal/posts/zysq8w9rwm9c
|
||||
// @ApiProperty({
|
||||
// type: Object,
|
||||
// description: "Optional metadata for the booking.",
|
||||
// example: { key: "value" },
|
||||
// required: false,
|
||||
// })
|
||||
// @IsObject()
|
||||
// @IsOptional()
|
||||
// metadata!: Record<string, unknown>;
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
description:
|
||||
"You can store any additional data you want here. Metadata must have at most 50 keys, each key up to 40 characters, and string values up to 500 characters.",
|
||||
example: { key: "value" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
@ValidateMetadata({
|
||||
message:
|
||||
"Metadata must have at most 50 keys, each key up to 40 characters, and string values up to 500 characters.",
|
||||
})
|
||||
metadata?: Record<string, string>;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
type: Object,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import type { ValidationOptions, ValidationArguments } from "class-validator";
|
||||
import { registerDecorator } from "class-validator";
|
||||
|
||||
export function ValidateMetadata(validationOptions?: ValidationOptions) {
|
||||
return function (object: any, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: "ValidateMetadata",
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(metadata: any) {
|
||||
if (typeof metadata !== "object" || metadata === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const keys = Object.keys(metadata);
|
||||
|
||||
if (keys.length > 50) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const key of keys) {
|
||||
if (key.length > 40) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isInvalidValidKeyValue(metadata[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
return `${args.property} must be an object with up to 50 keys, each key name up to 40 characters, and values with a maximum length of 500 characters.`;
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function isInvalidValidKeyValue(keyValue: any) {
|
||||
if (!isString(keyValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isTooLong(keyValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isString(keyValue: any): keyValue is string {
|
||||
return typeof keyValue === "string";
|
||||
}
|
||||
|
||||
function isTooLong(keyValue: string) {
|
||||
return keyValue.length > 500;
|
||||
}
|
||||
@@ -57,6 +57,16 @@ export class SeatedAttendee extends Attendee {
|
||||
@IsObject()
|
||||
@Expose()
|
||||
bookingFieldsResponses!: Record<string, unknown>;
|
||||
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
example: { key: "value" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
metadata?: Record<string, string>;
|
||||
}
|
||||
|
||||
class Host {
|
||||
@@ -189,6 +199,16 @@ class BaseBookingOutput_2024_08_13 {
|
||||
@IsBoolean()
|
||||
@Expose()
|
||||
absentHost!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
example: { key: "value" },
|
||||
required: false,
|
||||
})
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
@Expose()
|
||||
metadata?: Record<string, string>;
|
||||
}
|
||||
|
||||
export class BookingOutput_2024_08_13 extends BaseBookingOutput_2024_08_13 {
|
||||
|
||||
Reference in new issue
Block a user