Skip to content

Scheduling infrastructure for absolutely everyone.

feat: improve validations

Agusti Fernandez Pardo0e3131d8665b
diff --git a/lib/validations/apiKey.ts b/lib/validations/apiKey.ts
index 044e3768f37..a8d89d78f39 100644
--- a/lib/validations/apiKey.ts
+++ b/lib/validations/apiKey.ts
@@ -9,8 +9,7 @@ const schemaApiKey = z
expiresAt: z.date().optional(), // default is 30 days
note: z.string().min(1).optional(),
})
- .strict();
-
+ .strict(); // Adding strict so that we can disallow passing in extra fields
const withValidApiKey = withValidation({
schema: schemaApiKey,
type: "Zod",
diff --git a/lib/validations/availability.ts b/lib/validations/availability.ts
index d5fc7bbc258..1bffc5acec4 100644
--- a/lib/validations/availability.ts
+++ b/lib/validations/availability.ts
@@ -3,57 +3,15 @@ import { z } from "zod";
const schemaAvailability = z
.object({
- uid: z.string().min(3),
- title: z.string().min(3),
- description: z.string().min(3).optional(),
- startTime: z.date().or(z.string()),
- endTime: z.date(),
- location: z.string().min(3).optional(),
- createdAt: z.date().or(z.string()),
- updatedAt: z.date(),
- confirmed: z.boolean().default(true),
- rejected: z.boolean().default(false),
- paid: z.boolean().default(false),
-
- // bufferTime: z.number().default(0),
- // // attendees: z.array((schemaSchedule)).optional(),
-
- // startTime: z.string().min(3),
- // endTime: z.string().min(3),
- // email: z.string().email(), // max is a full day.
- // emailVerified: z.date().optional(),
- // password: z.string().optional(),
- // bio: z.string().min(3).optional(),
- // avatar: z.string().optional(),
- // timeZone: z.string().default("Europe/London"),
- // weekStart: z.string().default("Sunday"),
- // bufferTime: z.number().default(0),
- // theme: z.string().optional(),
- // trialEndsAt: z.date().optional(),
- // eventTypes: z.array((schemaEventType)).optional(),
- // // credentials: z.array((schemaCredentials)).optional(),
- // // teams: z.array((schemaMembership)).optional(),
- // // bookings: z.array((schemaAvailability)).optional(),
- // // schedules: z.array((schemaSchedule)).optional(),
- // defaultScheduleId: z.number().optional(),
- // // selectedCalendars: z.array((schemaSelectedCalendar)).optional(),
- // completedOnboarding: z.boolean().default(false),
- // locale: z.string().optional(),
- // timeFormat: z.number().optional().default(12),
- // twoFactorEnabled: z.boolean().default(false),
- // twoFactorSecret: z.string().optional(),
- // identityProvider: z.enum(["CAL", "SAML", "GOOGLE"]).optional().default("CAL"),
- // identityProviderId: z.string().optional(),
- // // availavility: z.array((schemaAvailavility)).optional(),
- // invitedTo: z.number().optional(),
- // plan: z.enum(['FREE', 'TRIAL', 'PRO']).default("TRIAL"),
- // // webhooks: z.array((schemaWebhook)).optional(),
- // brandColor: z.string().default("#292929"),
- // darkBrandColor: z.string().default("#fafafa"),
- // // destinationCalendar: z.instanceof(schemaEventType).optional(), // FIXME: instanceof doesnt work here
- // away: z.boolean().default(false),
- // metadata: z.object({}).optional(),
- // verified: z.boolean().default(false),
+ id: z.number(),
+ userId: z.number(),
+ eventTypeId: z.number(),
+ scheduleId: z.number(),
+
+ days: z.array(z.number()),
+ date: z.date().or(z.string()),
+ startTime: z.string(),
+ endTime: z.string(),
})
.strict();
const withValidAvailability = withValidation({
diff --git a/lib/validations/booking.ts b/lib/validations/booking.ts
index 3959ad9b244..7c07aac2833 100644
--- a/lib/validations/booking.ts
+++ b/lib/validations/booking.ts
@@ -10,7 +10,7 @@ const schemaBooking = z
endTime: z.date(),
location: z.string().min(3).optional(),
createdAt: z.date().or(z.string()),
- updatedAt: z.date(),
+ updatedAt: z.date().or(z.string()),
confirmed: z.boolean().default(true),
rejected: z.boolean().default(false),
paid: z.boolean().default(false),
diff --git a/lib/validations/membership.ts b/lib/validations/membership.ts
index 4959dafb8a0..3d52743955a 100644
--- a/lib/validations/membership.ts
+++ b/lib/validations/membership.ts
@@ -3,7 +3,7 @@ import { z } from "zod";
const schemaMembership = z
.object({})
- .strict(); // Adding strict so that we can disallow passing in extra fields
+ .strict();
const withValidMembership = withValidation({
schema: schemaMembership,
type: "Zod",
diff --git a/pages/api/attendees/[id]/delete.ts b/pages/api/attendees/[id]/delete.ts
index 47b4a783b70..21c0efaff44 100644
--- a/pages/api/attendees/[id]/delete.ts
+++ b/pages/api/attendees/[id]/delete.ts
@@ -21,7 +21,7 @@ export async function attendee(req: NextApiRequest, res: NextApiResponse<Respons
// This catches the error thrown by prisma.attendee.delete() if the resource is not found.
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
// Reject any other HTTP method than POST
- } else res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
}
export default withValidQueryIdTransformParseInt(attendee);
diff --git a/pages/api/availabilities/[id]/delete.ts b/pages/api/availabilities/[id]/delete.ts
index cd3c8408015..43db244859f 100644
--- a/pages/api/availabilities/[id]/delete.ts
+++ b/pages/api/availabilities/[id]/delete.ts
@@ -1,7 +1,6 @@
-import prisma from "@calcom/prisma";
-
import type { NextApiRequest, NextApiResponse } from "next";
+import prisma from "@calcom/prisma";
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
@@ -21,7 +20,7 @@ export async function availability(req: NextApiRequest, res: NextApiResponse<Res
// This catches the error thrown by prisma.availability.delete() if the resource is not found.
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
// Reject any other HTTP method than POST
- } else res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
+ } else res.status(405).json({ message: "Only DELETE Method allowed" });
}
export default withValidQueryIdTransformParseInt(availability);