Scheduling infrastructure for absolutely everyone.
Remove GET /availabilities (#188)
Alex van Andeldee0f6a415fa
diff --git a/pages/api/availabilities/_get.ts b/pages/api/availabilities/_get.tsdeleted file mode 100644index b0649b5b16d..00000000000--- a/pages/api/availabilities/_get.ts+++ /dev/null@@ -1,58 +0,0 @@-import type { NextApiRequest } from "next";--import { HttpError } from "@calcom/lib/http-error";-import { defaultResponder } from "@calcom/lib/server";--import { schemaAvailabilityReadBodyParams } from "@lib/validations/availability";--/**- * @swagger- * /availabilities:- * get:- * operationId: listAvailabilities- * summary: Find all availabilities- * tags:- * - availabilities- * externalDocs:- * url: https://docs.cal.com/availability- * responses:- * 200:- * description: OK- * 401:- * description: Authorization information is missing or invalid.- * 404:- * description: No availabilities were found- */-async function handler(req: NextApiRequest) {- const { userId, isAdmin, prisma } = req;- const body = schemaAvailabilityReadBodyParams.parse(req.body || {});-- if (body.userId && !isAdmin)- throw new HttpError({- statusCode: 401,- message: "Unauthorized: Only admins can request other users' availabilities",- });-- const userIds = Array.isArray(body.userId) ? body.userId : [body.userId || userId];-- let availabilities = await prisma.availability.findMany({- where: { Schedule: { userId: { in: userIds } } },- include: { Schedule: { select: { userId: true } } },- ...(Array.isArray(body.userId) && { orderBy: { userId: "asc" } }),- });-- /**- * IDK if this a special requirement but, since availabilities aren't directly related to a user.- * We manually override the `userId` field so the user doesn't need to query the scheduleId just- * to get the user that it belongs to... OR... we can just access `availability.Schedule.userId` instead- * but at this point I'm afraid to break something so we will have both for now... ¯\_(ツ)_/¯- */- availabilities = availabilities.map((a) => ({ ...a, userId: a.Schedule?.userId || null }));-- if (!availabilities.length)- throw new HttpError({ statusCode: 404, message: "No Availabilities were found" });-- return { availabilities };-}--export default defaultResponder(handler);diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.tsindex c07846423fa..3980d611ffe 100644--- a/pages/api/availabilities/index.ts+++ b/pages/api/availabilities/index.ts@@ -2,9 +2,8 @@ import { defaultHandler } from "@calcom/lib/server";import { withMiddleware } from "@lib/helpers/withMiddleware";-export default withMiddleware("HTTP_GET_OR_POST")(+export default withMiddleware()(defaultHandler({- GET: import("./_get"),POST: import("./_post"),}));diff --git a/pages/api/docs.ts b/pages/api/docs.tsindex 37fdddc06a4..230f4da80fb 100644--- a/pages/api/docs.ts+++ b/pages/api/docs.ts@@ -114,7 +114,10 @@ const swaggerHandler = withSwagger({{ name: "schedules" },{ name: "teams" },{ name: "memberships" },- { name: "availabilities" },+ {+ name: "availabilities",+ description: "Allows modifying unique availabilities tied to a schedule.",+ },{ name: "custom-inputs" },{ name: "event-references" },{ name: "booking-references" },