Adds basic availability endpoint

pull/9078/head
zomars 2022-06-14 15:17:09 -06:00
parent 3cb2a8b866
commit e1bcd38e61
2 changed files with 34 additions and 0 deletions

View File

@ -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);

View File

@ -0,0 +1,5 @@
import { defaultHandler } from "@calcom/lib/server";
export default defaultHandler({
GET: import("./_get"),
});