Skip to content

Scheduling infrastructure for absolutely everyone.

Adds basic availability endpoint

zomarse1bcd38e61c4
diff --git a/pages/api/availability/_get.ts b/pages/api/availability/_get.ts
new file mode 100644
index 00000000000..21450f005e1
--- /dev/null
+++ b/pages/api/availability/_get.ts
@@ -0,0 +1,29 @@
+import type { NextApiRequest } from "next";
+import { z } from "zod";
+
+import { getUserAvailability } from "@calcom/core/getUserAvailability";
+import { defaultResponder } from "@calcom/lib/server";
+import { stringOrNumber } from "@calcom/prisma/zod-utils";
+
+const availabilitySchema = z
+ .object({
+ userId: stringOrNumber.optional(),
+ username: z.string().optional(),
+ dateFrom: z.string(),
+ dateTo: z.string(),
+ eventTypeId: stringOrNumber.optional(),
+ })
+ .refine((data) => !!data.username || !!data.userId, "Either username or userId should be filled in.");
+
+async function handler(req: NextApiRequest) {
+ const { username, userId, eventTypeId, dateTo, dateFrom } = availabilitySchema.parse(req.query);
+ return getUserAvailability({
+ username,
+ dateFrom,
+ dateTo,
+ eventTypeId,
+ userId,
+ });
+}
+
+export default defaultResponder(handler);
diff --git a/pages/api/availability/index.ts b/pages/api/availability/index.ts
new file mode 100644
index 00000000000..0fe78366978
--- /dev/null
+++ b/pages/api/availability/index.ts
@@ -0,0 +1,5 @@
+import { defaultHandler } from "@calcom/lib/server";
+
+export default defaultHandler({
+ GET: import("./_get"),
+});