backend: Enhance roomIdPrefix transformation to remove leading hyphens

This commit is contained in:
Carlos Santos 2025-04-11 09:38:52 +02:00
parent ba40ab2747
commit 4671b579a2

View File

@ -62,15 +62,21 @@ const RoomRequestOptionsSchema: z.ZodType<MeetRoomOptions> = z.object({
.optional(), .optional(),
roomIdPrefix: z roomIdPrefix: z
.string() .string()
.transform( .transform((val) => {
(val) => let transformed = val
val .trim() // Remove leading and trailing spaces
.trim() // Remove leading and trailing spaces .replace(/\s+/g, '') // Remove all whitespace instead of replacing it with hyphens
.replace(/\s+/g, '') // Remove all whitespace instead of replacing it with hyphens .replace(/[^a-zA-Z0-9-]/g, '') // Remove any character except letters, numbers, and hyphens
.replace(/[^a-zA-Z0-9-]/g, '') // Remove any character except letters, numbers, and hyphens .replace(/-+/g, '-') // Replace multiple consecutive hyphens with a single one
.replace(/-+/g, '-') // Replace multiple consecutive hyphens with a single one .replace(/-+$/, ''); // Remove trailing hyphens
.replace(/-+$/, '') // Remove trailing hyphens
) // If the transformed string starts with a hyphen, remove it.
if (transformed.startsWith('-')) {
transformed = transformed.substring(1);
}
return transformed;
})
.optional() .optional()
.default(''), .default(''),
preferences: RoomPreferencesSchema.optional().default({ preferences: RoomPreferencesSchema.optional().default({
@ -93,8 +99,11 @@ const GetParticipantRoleSchema = z.object({
const GetRoomFiltersSchema: z.ZodType<MeetRoomFilters> = z.object({ const GetRoomFiltersSchema: z.ZodType<MeetRoomFilters> = z.object({
maxItems: z.coerce maxItems: z.coerce
.number() .number()
.int() .transform((val) => {
.transform((val) => (val > 100 ? 100 : val)) // Convert the value to a number
const intVal = Math.floor(val);
return intVal > 100 ? 100 : intVal;
})
.default(10), .default(10),
nextPageToken: z.string().optional(), nextPageToken: z.string().optional(),
fields: z.string().optional() fields: z.string().optional()