diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000000..0e71ec1eae --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require("@calcom/config/eslint-preset"); diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 0378cf43af..0000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,17 +0,0 @@ -// FIXME: import eslint-config-calcom-base from '@calcom/config/eslint -{ - "root": true, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended", - "plugin:@next/next/recommended" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { "project": ["./tsconfig.json"] }, - "plugins": ["@typescript-eslint", "prettier"], - "rules": { - "prettier/prettier": "error" - }, - "ignorePatterns": ["src/**/*.test.ts", "src/frontend/generated/*"] -} diff --git a/.prettierignore b/.prettierignore index 28b23b7d57..745ffcee46 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,5 @@ .next/ coverage/ node_modules/ -tests/ \ No newline at end of file +tests/ +templates/ \ No newline at end of file diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000000..246057aa0c --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1 @@ +module.exports = require("../../packages/config/prettier-preset"); diff --git a/json-schema/json-schema.json b/json-schema/json-schema.json index 220dbd101d..1ae113fddf 100644 --- a/json-schema/json-schema.json +++ b/json-schema/json-schema.json @@ -16,24 +16,14 @@ "description": "@zod.custom(imports.eventTypeSlug)" }, "description": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "position": { "type": "integer", "default": 0 }, "locations": { - "type": [ - "number", - "string", - "boolean", - "object", - "array", - "null" - ], + "type": ["number", "string", "boolean", "object", "array", "null"], "description": "@zod.custom(imports.eventTypeLocations)" }, "length": { @@ -50,10 +40,7 @@ } }, "userId": { - "type": [ - "integer", - "null" - ] + "type": ["integer", "null"] }, "team": { "anyOf": [ @@ -94,10 +81,7 @@ ] }, "eventName": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "customInputs": { "type": "array", @@ -106,45 +90,26 @@ } }, "timeZone": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "periodType": { "type": "string", "default": "UNLIMITED", - "enum": [ - "UNLIMITED", - "ROLLING", - "RANGE" - ] + "enum": ["UNLIMITED", "ROLLING", "RANGE"] }, "periodStartDate": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "format": "date-time" }, "periodEndDate": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "format": "date-time" }, "periodDays": { - "type": [ - "integer", - "null" - ] + "type": ["integer", "null"] }, "periodCountCalendarDays": { - "type": [ - "boolean", - "null" - ] + "type": ["boolean", "null"] }, "requiresConfirmation": { "type": "boolean", @@ -167,14 +132,8 @@ "default": 0 }, "schedulingType": { - "type": [ - "string", - "null" - ], - "enum": [ - "ROUND_ROBIN", - "COLLECTIVE" - ] + "type": ["string", "null"], + "enum": ["ROUND_ROBIN", "COLLECTIVE"] }, "schedule": { "anyOf": [ @@ -195,20 +154,10 @@ "default": "usd" }, "slotInterval": { - "type": [ - "integer", - "null" - ] + "type": ["integer", "null"] }, "metadata": { - "type": [ - "number", - "string", - "boolean", - "object", - "array", - "null" - ] + "type": ["number", "string", "boolean", "object", "array", "null"] } } }, @@ -222,14 +171,7 @@ "type": "string" }, "key": { - "type": [ - "number", - "string", - "boolean", - "object", - "array", - "null" - ] + "type": ["number", "string", "boolean", "object", "array", "null"] }, "user": { "anyOf": [ @@ -294,45 +236,27 @@ "type": "integer" }, "username": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "name": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "email": { "type": "string", "description": "@zod.email()" }, "emailVerified": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "format": "date-time" }, "password": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "bio": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "avatar": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "timeZone": { "type": "string", @@ -359,20 +283,14 @@ "default": false }, "theme": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "createdDate": { "type": "string", "format": "date-time" }, "trialEndsAt": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "format": "date-time" }, "eventTypes": { @@ -406,10 +324,7 @@ } }, "defaultScheduleId": { - "type": [ - "integer", - "null" - ] + "type": ["integer", "null"] }, "selectedCalendars": { "type": "array", @@ -422,23 +337,14 @@ "default": false }, "locale": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "timeFormat": { - "type": [ - "integer", - "null" - ], + "type": ["integer", "null"], "default": 12 }, "twoFactorSecret": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "twoFactorEnabled": { "type": "boolean", @@ -447,17 +353,10 @@ "identityProvider": { "type": "string", "default": "CAL", - "enum": [ - "CAL", - "GOOGLE", - "SAML" - ] + "enum": ["CAL", "GOOGLE", "SAML"] }, "identityProviderId": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "availability": { "type": "array", @@ -466,19 +365,12 @@ } }, "invitedTo": { - "type": [ - "integer", - "null" - ] + "type": ["integer", "null"] }, "plan": { "type": "string", "default": "TRIAL", - "enum": [ - "FREE", - "TRIAL", - "PRO" - ] + "enum": ["FREE", "TRIAL", "PRO"] }, "webhooks": { "type": "array", @@ -509,20 +401,10 @@ "default": false }, "metadata": { - "type": [ - "number", - "string", - "boolean", - "object", - "array", - "null" - ] + "type": ["number", "string", "boolean", "object", "array", "null"] }, "verified": { - "type": [ - "boolean", - "null" - ], + "type": ["boolean", "null"], "default": false }, "apiKeys": { @@ -540,28 +422,16 @@ "type": "integer" }, "name": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "slug": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "logo": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "bio": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "hideBranding": { "type": "boolean", @@ -590,11 +460,7 @@ }, "role": { "type": "string", - "enum": [ - "MEMBER", - "ADMIN", - "OWNER" - ] + "enum": ["MEMBER", "ADMIN", "OWNER"] }, "team": { "$ref": "#/definitions/Team" @@ -643,22 +509,13 @@ "type": "string" }, "meetingId": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "meetingPassword": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "meetingUrl": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "booking": { "anyOf": [ @@ -688,10 +545,7 @@ "type": "string" }, "locale": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "default": "en" }, "booking": { @@ -771,10 +625,7 @@ "type": "string" }, "description": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "startTime": { "type": "string", @@ -791,10 +642,7 @@ } }, "location": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "dailyRef": { "anyOf": [ @@ -811,10 +659,7 @@ "format": "date-time" }, "updatedAt": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "format": "date-time" }, "confirmed": { @@ -828,12 +673,7 @@ "status": { "type": "string", "default": "ACCEPTED", - "enum": [ - "CANCELLED", - "ACCEPTED", - "REJECTED", - "PENDING" - ] + "enum": ["CANCELLED", "ACCEPTED", "REJECTED", "PENDING"] }, "paid": { "type": "boolean", @@ -856,16 +696,10 @@ ] }, "cancellationReason": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "rejectionReason": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] } } }, @@ -892,10 +726,7 @@ "type": "string" }, "timeZone": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "availability": { "type": "array", @@ -946,10 +777,7 @@ "format": "date-time" }, "date": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "format": "date-time" }, "Schedule": { @@ -992,12 +820,7 @@ }, "type": { "type": "string", - "enum": [ - "TEXT", - "TEXTLONG", - "NUMBER", - "BOOL" - ] + "enum": ["TEXT", "TEXTLONG", "NUMBER", "BOOL"] }, "required": { "type": "boolean" @@ -1042,9 +865,7 @@ }, "reminderType": { "type": "string", - "enum": [ - "PENDING_BOOKING_CONFIRMATION" - ] + "enum": ["PENDING_BOOKING_CONFIRMATION"] }, "elapsedMinutes": { "type": "integer" @@ -1066,9 +887,7 @@ }, "type": { "type": "string", - "enum": [ - "STRIPE" - ] + "enum": ["STRIPE"] }, "booking": { "anyOf": [ @@ -1096,14 +915,7 @@ "type": "boolean" }, "data": { - "type": [ - "number", - "string", - "boolean", - "object", - "array", - "null" - ] + "type": ["number", "string", "boolean", "object", "array", "null"] }, "externalId": { "type": "string" @@ -1120,10 +932,7 @@ "type": "string" }, "payloadTemplate": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] }, "createdAt": { "type": "string", @@ -1135,11 +944,7 @@ }, "eventTriggers": { "type": "array", - "enum": [ - "BOOKING_CREATED", - "BOOKING_RESCHEDULED", - "BOOKING_CANCELLED" - ] + "enum": ["BOOKING_CREATED", "BOOKING_RESCHEDULED", "BOOKING_CANCELLED"] }, "user": { "anyOf": [ @@ -1188,10 +993,7 @@ "format": "date-time" }, "note": { - "type": [ - "string", - "null" - ] + "type": ["string", "null"] } } } @@ -1259,4 +1061,4 @@ "$ref": "#/definitions/ApiKey" } } -} \ No newline at end of file +} diff --git a/lib/helpers/httpMethods.ts b/lib/helpers/httpMethods.ts index d19102d4dc..1454355f3a 100644 --- a/lib/helpers/httpMethods.ts +++ b/lib/helpers/httpMethods.ts @@ -11,7 +11,19 @@ export const httpMethod = (allowedHttpMethod: "GET" | "POST" | "PATCH" | "DELETE }; }; +export const httpMethods = (allowedHttpMethod: string[]): NextMiddleware => { + return async function (req, res, next) { + if (allowedHttpMethod.map((method) => method === req.method)) { + await next(); + } else { + res.status(405).json({ message: `Only ${allowedHttpMethod} Method allowed` }); + res.end(); + } + }; +}; + export const HTTP_POST = httpMethod("POST"); export const HTTP_GET = httpMethod("GET"); export const HTTP_PATCH = httpMethod("PATCH"); export const HTTP_DELETE = httpMethod("DELETE"); +export const HTTP_GET_DELETE_PATCH = httpMethods(["GET", "DELETE", "PATCH"]); diff --git a/lib/helpers/withMiddleware.ts b/lib/helpers/withMiddleware.ts index e15c388d51..4171fa774f 100644 --- a/lib/helpers/withMiddleware.ts +++ b/lib/helpers/withMiddleware.ts @@ -2,11 +2,12 @@ import { label } from "next-api-middleware"; import { addRequestId } from "./addRequestid"; import { captureErrors } from "./captureErrors"; -import { HTTP_POST, HTTP_DELETE, HTTP_PATCH, HTTP_GET } from "./httpMethods"; +import { HTTP_POST, HTTP_DELETE, HTTP_PATCH, HTTP_GET, HTTP_GET_DELETE_PATCH } from "./httpMethods"; import { verifyApiKey } from "./verifyApiKey"; const withMiddleware = label( { + HTTP_GET_DELETE_PATCH, HTTP_GET, HTTP_PATCH, HTTP_POST, diff --git a/pages/api/api-keys/[id]/delete.ts b/pages/api/api-keys/[id]/delete.ts deleted file mode 100644 index dbe8250fe2..0000000000 --- a/pages/api/api-keys/[id]/delete.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -type ResponseData = { - message?: string; - error?: unknown; -}; - -export async function deleteApiKey(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdAsString.safeParse(req.query); - if (safe.success) { - const data = await prisma.apiKey.delete({ where: { id: safe.data.id } }); - // We only remove the apiKey type from the database if there's an existing resource. - if (data) res.status(200).json({ message: `ApiKey with id: ${safe.data.id} deleted successfully` }); - // This catches the error thrown by prisma.apiKey.delete() if the resource is not found. - else res.status(400).json({ message: `ApiKey with id: ${safe.data.id} was not able to be processed` }); - } -} - -export default withMiddleware("HTTP_DELETE", "addRequestId")(withValidQueryIdString(deleteApiKey)); diff --git a/pages/api/api-keys/[id]/edit.ts b/pages/api/api-keys/[id]/edit.ts deleted file mode 100644 index 66da3539bc..0000000000 --- a/pages/api/api-keys/[id]/edit.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; -import { ApiKey } from "@calcom/prisma/client"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/api-key"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -type ResponseData = { - data?: ApiKey; - message?: string; - error?: unknown; -}; - -export async function editApiKey(req: NextApiRequest, res: NextApiResponse) { - const { query, body } = req; - const safeQuery = await schemaQueryIdAsString.safeParse(query); - const safeBody = await schemaApiKeyBodyParams.safeParse(body); - - if (safeQuery.success && safeBody.success) { - const data = await prisma.apiKey.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - if (data) res.status(200).json({ data }); - else - (error: unknown) => - res - .status(404) - .json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error }); - } -} - -export default withMiddleware( - "HTTP_PATCH", - "addRequestId" -)(withValidQueryIdString(withValidApiKey(editApiKey))); diff --git a/pages/api/api-keys/[id]/index.ts b/pages/api/api-keys/[id]/index.ts deleted file mode 100644 index 36b9203667..0000000000 --- a/pages/api/api-keys/[id]/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; -import { ApiKey } from "@calcom/prisma/client"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -type ResponseData = { - data?: ApiKey; - error?: unknown; -}; - -export async function apiKeyById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdAsString.safeParse(req.query); - if (safe.success) { - const data = await prisma.apiKey.findUnique({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ data }); - else res.status(404).json({ error: { message: "ApiKey was not found" } }); - } -} - -export default withMiddleware("addRequestId", "HTTP_GET")(withValidQueryIdString(apiKeyById)); diff --git a/pages/api/api-keys/index.ts b/pages/api/api-keys/index.ts deleted file mode 100644 index 94074a940a..0000000000 --- a/pages/api/api-keys/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; -import { ApiKey } from "@calcom/prisma/client"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; - -type ResponseData = { - data?: ApiKey[]; - error?: unknown; -}; - -async function allApiKeys(req: NextApiRequest, res: NextApiResponse) { - const data = await prisma.apiKey.findMany(); - - if (data) res.status(200).json({ data }); - else res.status(400).json({ error: "No data found" }); -} - -export default withMiddleware("addRequestId", "HTTP_GET")(allApiKeys); diff --git a/pages/api/api-keys/new.ts b/pages/api/api-keys/new.ts deleted file mode 100644 index 160324c19c..0000000000 --- a/pages/api/api-keys/new.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; -import { ApiKey } from "@calcom/prisma/client"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/api-key"; - -type ResponseData = { - data?: ApiKey; - error?: unknown; -}; - -async function createApiKey(req: NextApiRequest, res: NextApiResponse) { - const safe = schemaApiKeyBodyParams.safeParse(req.body); - if (safe.success) { - const data = await prisma.apiKey.create({ data: safe.data }); - if (data) res.status(201).json({ data }); - else - (error: unknown) => res.status(400).json({ error: { message: "Could not create apiKey type", error } }); - } -} - -export default withMiddleware("addRequestId", "HTTP_POST")(withValidApiKey(createApiKey)); diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts new file mode 100644 index 0000000000..502fb5d1c5 --- /dev/null +++ b/pages/api/attendees/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { AttendeeResponse } from "@lib/types"; +import { schemaAttendeeBodyParams, schemaAttendeePublic } from "@lib/validations/attendee"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/attendees/{id}: + * get: + * summary: Get an attendee by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the attendee to get + * tags: + * - attendees + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Attendee was not found + * patch: + * summary: Edit an existing attendee + * consumes: + * - application/json + * parameters: + * - in: body + * name: attendee + * description: The attendee to edit + * schema: + * type: object + * $ref: '#/components/schemas/Attendee' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the attendee to edit + * tags: + * - attendees + * responses: + * 201: + * description: OK, attendee edited successfuly + * model: Attendee + * 400: + * description: Bad request. Attendee body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing attendee + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the attendee to delete + * tags: + * - attendees + * responses: + * 201: + * description: OK, attendee removed successfuly + * model: Attendee + * 400: + * description: Bad request. Attendee id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function attendeeById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaAttendeeBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.attendee + .findUnique({ where: { id: safeQuery.data.id } }) + .then((attendee) => schemaAttendeePublic.parse(attendee)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Attendee with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.attendee + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((attendee) => schemaAttendeePublic.parse(attendee)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Attendee with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.attendee + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `Attendee with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Attendee with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(attendeeById)); diff --git a/pages/api/attendees/[id]/delete.ts b/pages/api/attendees/[id]/delete.ts deleted file mode 100644 index 25e0818960..0000000000 --- a/pages/api/attendees/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/attendees/{id}/delete: - * delete: - * summary: Remove an existing attendee - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the attendee to delete - * tags: - * - attendees - * responses: - * 201: - * description: OK, attendee removed successfuly - * model: Attendee - * 400: - * description: Bad request. Attendee id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteAttendee(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.attendee.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `Attendee with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Attendee with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteAttendee)); diff --git a/pages/api/attendees/[id]/edit.ts b/pages/api/attendees/[id]/edit.ts deleted file mode 100644 index dab8ed979c..0000000000 --- a/pages/api/attendees/[id]/edit.ts +++ /dev/null @@ -1,58 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { AttendeeResponse } from "@lib/types"; -import { schemaAttendeeBodyParams, schemaAttendeePublic, withValidAttendee } from "@lib/validations/attendee"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/attendees/{id}/edit: - * patch: - * summary: Edit an existing attendee - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the attendee to edit - * tags: - * - attendees - * responses: - * 201: - * description: OK, attendee edited successfuly - * model: Attendee - * 400: - * description: Bad request. Attendee body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editAttendee(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaAttendeeBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const attendee = await prisma.attendee.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaAttendeePublic.parse(attendee); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidAttendee(editAttendee)) -); diff --git a/pages/api/attendees/[id]/index.ts b/pages/api/attendees/[id]/index.ts deleted file mode 100644 index 81f9ead1bd..0000000000 --- a/pages/api/attendees/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { AttendeeResponse } from "@lib/types"; -import { schemaAttendeePublic } from "@lib/validations/attendee"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/attendees/{id}: - * get: - * summary: Get a attendee by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the attendee to get - * tags: - * - attendees - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Attendee was not found - */ -export async function attendeeById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const attendee = await prisma.attendee.findUnique({ where: { id: safe.data.id } }); - const data = schemaAttendeePublic.parse(attendee); - - if (attendee) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Attendee was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(attendeeById)); diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts new file mode 100644 index 0000000000..be9d9eb987 --- /dev/null +++ b/pages/api/availabilities/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { AvailabilityResponse } from "@lib/types"; +import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/validations/availability"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/availabilities/{id}: + * get: + * summary: Get an availability by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the availability to get + * tags: + * - availabilities + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Availability was not found + * patch: + * summary: Edit an existing availability + * consumes: + * - application/json + * parameters: + * - in: body + * name: availability + * description: The availability to edit + * schema: + * type: object + * $ref: '#/components/schemas/Availability' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the availability to edit + * tags: + * - availabilities + * responses: + * 201: + * description: OK, availability edited successfuly + * model: Availability + * 400: + * description: Bad request. Availability body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing availability + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the availability to delete + * tags: + * - availabilities + * responses: + * 201: + * description: OK, availability removed successfuly + * model: Availability + * 400: + * description: Bad request. Availability id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function availabilityById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaAvailabilityBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.availability + .findUnique({ where: { id: safeQuery.data.id } }) + .then((availability) => schemaAvailabilityPublic.parse(availability)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Availability with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.availability + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((availability) => schemaAvailabilityPublic.parse(availability)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Availability with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.availability + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `Availability with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Availability with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(availabilityById)); diff --git a/pages/api/availabilities/[id]/delete.ts b/pages/api/availabilities/[id]/delete.ts deleted file mode 100644 index a23f5e9792..0000000000 --- a/pages/api/availabilities/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/availabilites/{id}/delete: - * delete: - * summary: Remove an existing availability - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the availability to delete - * tags: - * - availabilites - * responses: - * 201: - * description: OK, availability removed successfuly - * model: Availability - * 400: - * description: Bad request. Availability id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteAvailability(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.availability.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `Availability with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Availability with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteAvailability)); diff --git a/pages/api/availabilities/[id]/edit.ts b/pages/api/availabilities/[id]/edit.ts deleted file mode 100644 index 2aeb92dee2..0000000000 --- a/pages/api/availabilities/[id]/edit.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { AvailabilityResponse } from "@lib/types"; -import { - schemaAvailabilityBodyParams, - schemaAvailabilityPublic, - withValidAvailability, -} from "@lib/validations/availability"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/availabilites/{id}/edit: - * patch: - * summary: Edit an existing availability - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the availability to edit - * tags: - * - availabilites - * responses: - * 201: - * description: OK, availability edited successfuly - * model: Availability - * 400: - * description: Bad request. Availability body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editAvailability(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaAvailabilityBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const availability = await prisma.availability.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaAvailabilityPublic.parse(availability); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidAvailability(editAvailability)) -); diff --git a/pages/api/availabilities/[id]/index.ts b/pages/api/availabilities/[id]/index.ts deleted file mode 100644 index 054c32ee9f..0000000000 --- a/pages/api/availabilities/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { AvailabilityResponse } from "@lib/types"; -import { schemaAvailabilityPublic } from "@lib/validations/availability"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/availabilites/{id}: - * get: - * summary: Get a availability by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the availability to get - * tags: - * - availabilites - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Availability was not found - */ -export async function availabilityById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const availability = await prisma.availability.findUnique({ where: { id: safe.data.id } }); - const data = schemaAvailabilityPublic.parse(availability); - - if (availability) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Availability was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(availabilityById)); diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts new file mode 100644 index 0000000000..8c804321e0 --- /dev/null +++ b/pages/api/booking-references/[id].ts @@ -0,0 +1,138 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { BookingReferenceResponse } from "@lib/types"; +import { + schemaBookingReferenceBodyParams, + schemaBookingReferencePublic, +} from "@lib/validations/booking-reference"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/booking-references/{id}: + * get: + * summary: Get a daily event reference by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the daily event reference to get + * tags: + * - booking-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: BookingReference was not found + * patch: + * summary: Edit an existing daily event reference + * consumes: + * - application/json + * parameters: + * - in: body + * name: bookingReference + * description: The bookingReference to edit + * schema: + * type: object + * $ref: '#/components/schemas/BookingReference' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the daily event reference to edit + * tags: + * - booking-references + * responses: + * 201: + * description: OK, bookingReference edited successfuly + * model: BookingReference + * 400: + * description: Bad request. BookingReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing daily event reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the daily event reference to delete + * tags: + * - booking-references + * responses: + * 201: + * description: OK, bookingReference removed successfuly + * model: BookingReference + * 400: + * description: Bad request. BookingReference id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function bookingReferenceById( + req: NextApiRequest, + res: NextApiResponse +) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaBookingReferenceBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.bookingReference + .findUnique({ where: { id: safeQuery.data.id } }) + .then((data) => schemaBookingReferencePublic.parse(data)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `BookingReference with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.bookingReference + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((bookingReference) => schemaBookingReferencePublic.parse(bookingReference)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `BookingReference with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.bookingReference + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `BookingReference with id: ${safeQuery.data.id} deleted` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `BookingReference with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")( + withValidQueryIdTransformParseInt(bookingReferenceById) +); diff --git a/pages/api/booking-references/[id]/delete.ts b/pages/api/booking-references/[id]/delete.ts deleted file mode 100644 index 1fb0f32eb2..0000000000 --- a/pages/api/booking-references/[id]/delete.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/booking-references/{id}/delete: - * delete: - * summary: Remove an existing bookingReference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the bookingReference to delete - * tags: - * - booking-references - * responses: - * 201: - * description: OK, bookingReference removed successfuly - * model: BookingReference - * 400: - * description: Bad request. BookingReference id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteBookingReference(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.bookingReference.delete({ where: { id: safe.data.id } }); - - if (data) - res.status(200).json({ message: `BookingReference with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `BookingReference with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteBookingReference)); diff --git a/pages/api/booking-references/[id]/edit.ts b/pages/api/booking-references/[id]/edit.ts deleted file mode 100644 index 60c5d53316..0000000000 --- a/pages/api/booking-references/[id]/edit.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BookingReferenceResponse } from "@lib/types"; -import { - schemaBookingReferenceBodyParams, - schemaBookingReferencePublic, - withValidBookingReference, -} from "@lib/validations/booking-reference"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/booking-references/{id}/edit: - * patch: - * summary: Edit an existing bookingReference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the bookingReference to edit - * tags: - * - booking-references - * responses: - * 201: - * description: OK, bookingReference edited successfuly - * model: BookingReference - * 400: - * description: Bad request. BookingReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editBookingReference( - req: NextApiRequest, - res: NextApiResponse -) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaBookingReferenceBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const bookingReference = await prisma.bookingReference.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaBookingReferencePublic.parse(bookingReference); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidBookingReference(editBookingReference)) -); diff --git a/pages/api/booking-references/[id]/index.ts b/pages/api/booking-references/[id]/index.ts deleted file mode 100644 index e71f6920d7..0000000000 --- a/pages/api/booking-references/[id]/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BookingReferenceResponse } from "@lib/types"; -import { schemaBookingReferencePublic } from "@lib/validations/booking-reference"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/booking-references/{id}: - * get: - * summary: Get a bookingReference by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the bookingReference to get - * tags: - * - booking-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: BookingReference was not found - */ -export async function bookingReferenceById( - req: NextApiRequest, - res: NextApiResponse -) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const bookingReference = await prisma.bookingReference.findUnique({ where: { id: safe.data.id } }); - const data = schemaBookingReferencePublic.parse(bookingReference); - - if (bookingReference) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "BookingReference was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(bookingReferenceById)); diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts new file mode 100644 index 0000000000..57b817464d --- /dev/null +++ b/pages/api/bookings/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { BookingResponse } from "@lib/types"; +import { schemaBookingBodyParams, schemaBookingPublic } from "@lib/validations/booking"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/bookings/{id}: + * get: + * summary: Get a booking by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking to get + * tags: + * - bookings + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Booking was not found + * patch: + * summary: Edit an existing booking + * consumes: + * - application/json + * parameters: + * - in: body + * name: booking + * description: The booking to edit + * schema: + * type: object + * $ref: '#/components/schemas/Booking' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking to edit + * tags: + * - bookings + * responses: + * 201: + * description: OK, booking edited successfuly + * model: Booking + * 400: + * description: Bad request. Booking body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing booking + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the booking to delete + * tags: + * - bookings + * responses: + * 201: + * description: OK, booking removed successfuly + * model: Booking + * 400: + * description: Bad request. Booking id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function bookingById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaBookingBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.booking + .findUnique({ where: { id: safeQuery.data.id } }) + .then((booking) => schemaBookingPublic.parse(booking)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Booking with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.booking + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((booking) => schemaBookingPublic.parse(booking)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Booking with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.booking + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `Booking with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Booking with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(bookingById)); diff --git a/pages/api/bookings/[id]/delete.ts b/pages/api/bookings/[id]/delete.ts deleted file mode 100644 index 3905a93b03..0000000000 --- a/pages/api/bookings/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/bookings/{id}/delete: - * delete: - * summary: Remove an existing booking - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking to delete - * tags: - * - bookings - * responses: - * 201: - * description: OK, booking removed successfuly - * model: Booking - * 400: - * description: Bad request. Booking id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteBooking(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.booking.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `Booking with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Booking with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteBooking)); diff --git a/pages/api/bookings/[id]/edit.ts b/pages/api/bookings/[id]/edit.ts deleted file mode 100644 index fffc48c221..0000000000 --- a/pages/api/bookings/[id]/edit.ts +++ /dev/null @@ -1,56 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BookingResponse } from "@lib/types"; -import { schemaBookingBodyParams, schemaBookingPublic, withValidBooking } from "@lib/validations/booking"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/bookings/{id}/edit: - * patch: - * summary: Edit an existing booking - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking to edit - * tags: - * - bookings - * responses: - * 201: - * description: OK, booking edited successfuly - * model: Booking - * 400: - * description: Bad request. Booking body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editBooking(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaBookingBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const booking = await prisma.booking.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaBookingPublic.parse(booking); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")(withValidQueryIdTransformParseInt(withValidBooking(editBooking))); diff --git a/pages/api/bookings/[id]/index.ts b/pages/api/bookings/[id]/index.ts deleted file mode 100644 index c2b47d737f..0000000000 --- a/pages/api/bookings/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BookingResponse } from "@lib/types"; -import { schemaBookingPublic } from "@lib/validations/booking"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/bookings/{id}: - * get: - * summary: Get a booking by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the booking to get - * tags: - * - bookings - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Booking was not found - */ -export async function bookingById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const booking = await prisma.booking.findUnique({ where: { id: safe.data.id } }); - const data = schemaBookingPublic.parse(booking); - - if (booking) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Booking was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(bookingById)); diff --git a/pages/api/credentials/[id].ts b/pages/api/credentials/[id].ts new file mode 100644 index 0000000000..cc48ffab6a --- /dev/null +++ b/pages/api/credentials/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { CredentialResponse } from "@lib/types"; +import { schemaCredentialBodyParams, schemaCredentialPublic } from "@lib/validations/credential"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/credentials/{id}: + * get: + * summary: Get a credential by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the credential to get + * tags: + * - credentials + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Credential was not found + * patch: + * summary: Edit an existing credential + * consumes: + * - application/json + * parameters: + * - in: body + * name: credential + * description: The credential to edit + * schema: + * type: object + * $ref: '#/components/schemas/Credential' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the credential to edit + * tags: + * - credentials + * responses: + * 201: + * description: OK, credential edited successfuly + * model: Credential + * 400: + * description: Bad request. Credential body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing credential + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the credential to delete + * tags: + * - credentials + * responses: + * 201: + * description: OK, credential removed successfuly + * model: Credential + * 400: + * description: Bad request. Credential id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function credentialById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaCredentialBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.credential + .findUnique({ where: { id: safeQuery.data.id } }) + .then((credential) => schemaCredentialPublic.parse(credential)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Credential with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.credential + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((credential) => schemaCredentialPublic.parse(credential)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Credential with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.credential + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `Credential with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Credential with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(credentialById)); diff --git a/pages/api/credentials/[id]/delete.ts b/pages/api/credentials/[id]/delete.ts deleted file mode 100644 index 49e4918792..0000000000 --- a/pages/api/credentials/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/credentials/{id}/delete: - * delete: - * summary: Remove an existing credential - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the credential to delete - * tags: - * - credentials - * responses: - * 201: - * description: OK, credential removed successfuly - * model: Credential - * 400: - * description: Bad request. Credential id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteCredential(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.credential.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `Credential with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Credential with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteCredential)); diff --git a/pages/api/credentials/[id]/edit.ts b/pages/api/credentials/[id]/edit.ts deleted file mode 100644 index 69883de41e..0000000000 --- a/pages/api/credentials/[id]/edit.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { CredentialResponse } from "@lib/types"; -import { - schemaCredentialBodyParams, - schemaCredentialPublic, - withValidCredential, -} from "@lib/validations/credential"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/credentials/{id}/edit: - * patch: - * summary: Edit an existing credential - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the credential to edit - * tags: - * - credentials - * responses: - * 201: - * description: OK, credential edited successfuly - * model: Credential - * 400: - * description: Bad request. Credential body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editCredential(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaCredentialBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const credential = await prisma.credential.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaCredentialPublic.parse(credential); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidCredential(editCredential)) -); diff --git a/pages/api/credentials/[id]/index.ts b/pages/api/credentials/[id]/index.ts deleted file mode 100644 index f20fa4ba5c..0000000000 --- a/pages/api/credentials/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { CredentialResponse } from "@lib/types"; -import { schemaCredentialPublic } from "@lib/validations/credential"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/credentials/{id}: - * get: - * summary: Get a credential by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the credential to get - * tags: - * - credentials - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Credential was not found - */ -export async function credentialById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const credential = await prisma.credential.findUnique({ where: { id: safe.data.id } }); - const data = schemaCredentialPublic.parse(credential); - - if (credential) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Credential was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(credentialById)); diff --git a/pages/api/daily-event-references/[id].ts b/pages/api/daily-event-references/[id].ts new file mode 100644 index 0000000000..21072a7a4e --- /dev/null +++ b/pages/api/daily-event-references/[id].ts @@ -0,0 +1,144 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { DailyEventReferenceResponse } from "@lib/types"; +import { + schemaDailyEventReferenceBodyParams, + schemaDailyEventReferencePublic, +} from "@lib/validations/daily-event-reference"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/daily-event-references/{id}: + * get: + * summary: Get a daily event reference by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the daily event reference to get + * tags: + * - daily-event-references + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: DailyEventReference was not found + * patch: + * summary: Edit an existing daily event reference + * consumes: + * - application/json + * parameters: + * - in: body + * name: dailyEventReference + * description: The dailyEventReference to edit + * schema: + * type: object + * $ref: '#/components/schemas/DailyEventReference' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the daily event reference to edit + * tags: + * - daily-event-references + * responses: + * 201: + * description: OK, dailyEventReference edited successfuly + * model: DailyEventReference + * 400: + * description: Bad request. DailyEventReference body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing daily event reference + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the daily event reference to delete + * tags: + * - daily-event-references + * responses: + * 201: + * description: OK, dailyEventReference removed successfuly + * model: DailyEventReference + * 400: + * description: Bad request. DailyEventReference id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function dailyEventReferenceById( + req: NextApiRequest, + res: NextApiResponse +) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaDailyEventReferenceBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.dailyEventReference + .findUnique({ where: { id: safeQuery.data.id } }) + .then((data) => schemaDailyEventReferencePublic.parse(data)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res + .status(404) + .json({ message: `DailyEventReference with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.dailyEventReference + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((dailyEventReference) => schemaDailyEventReferencePublic.parse(dailyEventReference)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res + .status(404) + .json({ message: `DailyEventReference with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.dailyEventReference + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `DailyEventReference with id: ${safeQuery.data.id} deleted` }) + ) + .catch((error: Error) => + res + .status(404) + .json({ message: `DailyEventReference with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")( + withValidQueryIdTransformParseInt(dailyEventReferenceById) +); diff --git a/pages/api/daily-event-references/[id]/delete.ts b/pages/api/daily-event-references/[id]/delete.ts deleted file mode 100644 index 1e020c65ff..0000000000 --- a/pages/api/daily-event-references/[id]/delete.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/daily-event-references/{id}/delete: - * delete: - * summary: Remove an existing dailyEventReference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the dailyEventReference to delete - * tags: - * - daily-event-references - * responses: - * 201: - * description: OK, dailyEventReference removed successfuly - * model: DailyEventReference - * 400: - * description: Bad request. DailyEventReference id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteDailyEventReference(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.dailyEventReference.delete({ where: { id: safe.data.id } }); - - if (data) - res.status(200).json({ message: `DailyEventReference with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `DailyEventReference with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteDailyEventReference)); diff --git a/pages/api/daily-event-references/[id]/edit.ts b/pages/api/daily-event-references/[id]/edit.ts deleted file mode 100644 index b090962717..0000000000 --- a/pages/api/daily-event-references/[id]/edit.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { DailyEventReferenceResponse } from "@lib/types"; -import { - schemaDailyEventReferenceBodyParams, - schemaDailyEventReferencePublic, - withValidDailyEventReference, -} from "@lib/validations/daily-event-reference"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/daily-event-references/{id}/edit: - * patch: - * summary: Edit an existing dailyEventReference - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the dailyEventReference to edit - * tags: - * - daily-event-references - * responses: - * 201: - * description: OK, dailyEventReference edited successfuly - * model: DailyEventReference - * 400: - * description: Bad request. DailyEventReference body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editDailyEventReference( - req: NextApiRequest, - res: NextApiResponse -) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaDailyEventReferenceBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const dailyEventReference = await prisma.dailyEventReference.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaDailyEventReferencePublic.parse(dailyEventReference); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidDailyEventReference(editDailyEventReference)) -); diff --git a/pages/api/daily-event-references/[id]/index.ts b/pages/api/daily-event-references/[id]/index.ts deleted file mode 100644 index 2ff523bc41..0000000000 --- a/pages/api/daily-event-references/[id]/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { DailyEventReferenceResponse } from "@lib/types"; -import { schemaDailyEventReferencePublic } from "@lib/validations/daily-event-reference"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/daily-event-references/{id}: - * get: - * summary: Get a dailyEventReference by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the dailyEventReference to get - * tags: - * - daily-event-references - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: DailyEventReference was not found - */ -export async function dailyEventReferenceById( - req: NextApiRequest, - res: NextApiResponse -) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const dailyEventReference = await prisma.dailyEventReference.findUnique({ where: { id: safe.data.id } }); - const data = schemaDailyEventReferencePublic.parse(dailyEventReference); - - if (dailyEventReference) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "DailyEventReference was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(dailyEventReferenceById)); diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].ts new file mode 100644 index 0000000000..a08406f9fa --- /dev/null +++ b/pages/api/destination-calendars/[id].ts @@ -0,0 +1,144 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { DestinationCalendarResponse } from "@lib/types"; +import { + schemaDestinationCalendarBodyParams, + schemaDestinationCalendarPublic, +} from "@lib/validations/destination-calendar"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/destination-calendars/{id}: + * get: + * summary: Get a destination calendar by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to get + * tags: + * - destination-calendars + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: DestinationCalendar was not found + * patch: + * summary: Edit an existing destination calendar + * consumes: + * - application/json + * parameters: + * - in: body + * name: destinationCalendar + * description: The destinationCalendar to edit + * schema: + * type: object + * $ref: '#/components/schemas/DestinationCalendar' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to edit + * tags: + * - destination-calendars + * responses: + * 201: + * description: OK, destinationCalendar edited successfuly + * model: DestinationCalendar + * 400: + * description: Bad request. DestinationCalendar body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing destination calendar + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the destination calendar to delete + * tags: + * - destination-calendars + * responses: + * 201: + * description: OK, destinationCalendar removed successfuly + * model: DestinationCalendar + * 400: + * description: Bad request. DestinationCalendar id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function destionationCalendarById( + req: NextApiRequest, + res: NextApiResponse +) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaDestinationCalendarBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.destinationCalendar + .findUnique({ where: { id: safeQuery.data.id } }) + .then((data) => schemaDestinationCalendarPublic.parse(data)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res + .status(404) + .json({ message: `DestinationCalendar with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.destinationCalendar + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((destinationCalendar) => schemaDestinationCalendarPublic.parse(destinationCalendar)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res + .status(404) + .json({ message: `DestinationCalendar with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.destinationCalendar + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `DestinationCalendar with id: ${safeQuery.data.id} deleted` }) + ) + .catch((error: Error) => + res + .status(404) + .json({ message: `DestinationCalendar with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")( + withValidQueryIdTransformParseInt(destionationCalendarById) +); diff --git a/pages/api/destination-calendars/[id]/delete.ts b/pages/api/destination-calendars/[id]/delete.ts deleted file mode 100644 index 1bf35128f9..0000000000 --- a/pages/api/destination-calendars/[id]/delete.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/destination-calendars/{id}/delete: - * delete: - * summary: Remove an existing destinationCalendar - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the destinationCalendar to delete - * tags: - * - destination-calendars - * responses: - * 201: - * description: OK, destinationCalendar removed successfuly - * model: DestinationCalendar - * 400: - * description: Bad request. DestinationCalendar id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteDestinationCalendar(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.destinationCalendar.delete({ where: { id: safe.data.id } }); - - if (data) - res.status(200).json({ message: `DestinationCalendar with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `DestinationCalendar with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteDestinationCalendar)); diff --git a/pages/api/destination-calendars/[id]/edit.ts b/pages/api/destination-calendars/[id]/edit.ts deleted file mode 100644 index ab09db2f4d..0000000000 --- a/pages/api/destination-calendars/[id]/edit.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { DestinationCalendarResponse } from "@lib/types"; -import { - schemaDestinationCalendarBodyParams, - schemaDestinationCalendarPublic, - withValidDestinationCalendar, -} from "@lib/validations/destination-calendar"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/destination-calendars/{id}/edit: - * patch: - * summary: Edit an existing destinationCalendar - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the destinationCalendar to edit - * tags: - * - destination-calendars - * responses: - * 201: - * description: OK, destinationCalendar edited successfuly - * model: DestinationCalendar - * 400: - * description: Bad request. DestinationCalendar body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editDestinationCalendar( - req: NextApiRequest, - res: NextApiResponse -) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaDestinationCalendarBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const destinationCalendar = await prisma.destinationCalendar.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaDestinationCalendarPublic.parse(destinationCalendar); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidDestinationCalendar(editDestinationCalendar)) -); diff --git a/pages/api/destination-calendars/[id]/index.ts b/pages/api/destination-calendars/[id]/index.ts deleted file mode 100644 index 4a7474ff7c..0000000000 --- a/pages/api/destination-calendars/[id]/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { DestinationCalendarResponse } from "@lib/types"; -import { schemaDestinationCalendarPublic } from "@lib/validations/destination-calendar"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/destination-calendars/{id}: - * get: - * summary: Get a destinationCalendar by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the destinationCalendar to get - * tags: - * - destination-calendars - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: DestinationCalendar was not found - */ -export async function destinationCalendarById( - req: NextApiRequest, - res: NextApiResponse -) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const destinationCalendar = await prisma.destinationCalendar.findUnique({ where: { id: safe.data.id } }); - const data = schemaDestinationCalendarPublic.parse(destinationCalendar); - - if (destinationCalendar) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "DestinationCalendar was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(destinationCalendarById)); diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts index fc3493bf28..b031b8a27e 100644 --- a/pages/api/destination-calendars/index.ts +++ b/pages/api/destination-calendars/index.ts @@ -10,7 +10,7 @@ import { schemaDestinationCalendarPublic } from "@lib/validations/destination-ca * @swagger * /api/destination-calendars: * get: - * summary: Get all destinationCalendars + * summary: Get all destination calendars * tags: * - destination-calendars * responses: diff --git a/pages/api/destination-calendars/new.ts b/pages/api/destination-calendars/new.ts index eac1e2e110..e98472b216 100644 --- a/pages/api/destination-calendars/new.ts +++ b/pages/api/destination-calendars/new.ts @@ -14,7 +14,7 @@ import { * @swagger * /api/destination-calendars/new: * post: - * summary: Creates a new destinationCalendar + * summary: Creates a new destination calendar * requestBody: * description: Optional description in *Markdown* * required: true diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/event-type-custom-inputs/[id].ts new file mode 100644 index 0000000000..8b5d29ed8f --- /dev/null +++ b/pages/api/event-type-custom-inputs/[id].ts @@ -0,0 +1,133 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { EventTypeCustomInputResponse } from "@lib/types"; +import { + schemaEventTypeCustomInputBodyParams, + schemaEventTypeCustomInputPublic, +} from "@lib/validations/event-type-custom-input"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/event-type-custom-inputs/{id}: + * get: + * summary: Get a eventTypeCustomInput by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the eventTypeCustomInput to get + * tags: + * - event-type-custom-inputs + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * deCustomInputscription: EventType was not found + * patch: + * summary: Edit an existing eventTypeCustomInput + * consumes: + * - application/json + * parameters: + * - in: body + * name: eventTypeCustomInput + * description: The eventTypeCustomInput to edit + * schema: + * type: object + * $ref: '#/comCustomInputponents/schemas/EventType' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the eventTypeCustomInput to edit + * tags: + * - event-type-custom-inputs + * responses: + * 201: + * description: OK, eventTypeCustomInput edited successfuly + * model: EventTypeCustomInput + * 400: + * desCustomInputcription: Bad request. EventType body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing eventTypeCustomInput + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the eventTypeCustomInput to delete + * tags: + * - event-type-custom-inputs + * responses: + * 201: + * description: OK, eventTypeCustomInput removed successfuly + * model: EventTypeCustomInput + * 400: + * desCustomInputcription: Bad request. EventType id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +async function eventTypeById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaEventTypeCustomInputBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.eventTypeCustomInput + .findUnique({ where: { id: safeQuery.data.id } }) + .then((data) => schemaEventTypeCustomInputPublic.parse(data)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.eventTypeCustomInput + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((eventTypeCustomInput) => schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.eventTypeCustomInput + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `CustomInputEventType with id: ${safeQuery.data.id} deleted` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(eventTypeById)); diff --git a/pages/api/event-type-custom-inputs/[id]/delete.ts b/pages/api/event-type-custom-inputs/[id]/delete.ts deleted file mode 100644 index e9064dd69d..0000000000 --- a/pages/api/event-type-custom-inputs/[id]/delete.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/event-type-custom-inputs/{id}/delete: - * delete: - * summary: Remove an existing eventTypeCustomInput - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventTypeCustomInput to delete - * tags: - * - event-type-custom-inputs - * responses: - * 201: - * description: OK, eventTypeCustomInput removed successfuly - * model: EventTypeCustomInput - * 400: - * description: Bad request. EventTypeCustomInput id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.eventTypeCustomInput.delete({ where: { id: safe.data.id } }); - - if (data) - res.status(200).json({ message: `EventTypeCustomInput with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `EventTypeCustomInput with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteEventTypeCustomInput)); diff --git a/pages/api/event-type-custom-inputs/[id]/edit.ts b/pages/api/event-type-custom-inputs/[id]/edit.ts deleted file mode 100644 index 0357d22aff..0000000000 --- a/pages/api/event-type-custom-inputs/[id]/edit.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { EventTypeCustomInputResponse } from "@lib/types"; -import { - schemaEventTypeCustomInputBodyParams, - schemaEventTypeCustomInputPublic, - withValidEventTypeCustomInput, -} from "@lib/validations/event-type-custom-input"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/event-type-custom-inputs/{id}/edit: - * patch: - * summary: Edit an existing eventTypeCustomInput - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventTypeCustomInput to edit - * tags: - * - event-type-custom-inputs - * responses: - * 201: - * description: OK, eventTypeCustomInput edited successfuly - * model: EventTypeCustomInput - * 400: - * description: Bad request. EventTypeCustomInput body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editEventTypeCustomInput( - req: NextApiRequest, - res: NextApiResponse -) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaEventTypeCustomInputBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const eventTypeCustomInput = await prisma.eventTypeCustomInput.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidEventTypeCustomInput(editEventTypeCustomInput)) -); diff --git a/pages/api/event-type-custom-inputs/[id]/index.ts b/pages/api/event-type-custom-inputs/[id]/index.ts deleted file mode 100644 index b99b067b9e..0000000000 --- a/pages/api/event-type-custom-inputs/[id]/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { EventTypeCustomInputResponse } from "@lib/types"; -import { schemaEventTypeCustomInputPublic } from "@lib/validations/event-type-custom-input"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/event-type-custom-inputs/{id}: - * get: - * summary: Get a eventTypeCustomInput by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventTypeCustomInput to get - * tags: - * - event-type-custom-inputs - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: EventTypeCustomInput was not found - */ -export async function eventTypeCustomInputById( - req: NextApiRequest, - res: NextApiResponse -) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const eventTypeCustomInput = await prisma.eventTypeCustomInput.findUnique({ where: { id: safe.data.id } }); - const data = schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput); - - if (eventTypeCustomInput) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "EventTypeCustomInput was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(eventTypeCustomInputById)); diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts new file mode 100644 index 0000000000..bf94bcdfa0 --- /dev/null +++ b/pages/api/event-types/[id].ts @@ -0,0 +1,128 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { EventTypeResponse } from "@lib/types"; +import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/event-types/{id}: + * get: + * summary: Get a eventType by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the eventType to get + * tags: + * - event-types + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: EventType was not found + * patch: + * summary: Edit an existing eventType + * consumes: + * - application/json + * parameters: + * - in: body + * name: eventType + * description: The eventType to edit + * schema: + * type: object + * $ref: '#/components/schemas/EventType' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the eventType to edit + * tags: + * - event-types + * responses: + * 201: + * description: OK, eventType edited successfuly + * model: EventType + * 400: + * description: Bad request. EventType body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing eventType + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the eventType to delete + * tags: + * - event-types + * responses: + * 201: + * description: OK, eventType removed successfuly + * model: EventType + * 400: + * description: Bad request. EventType id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function eventTypeById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaEventTypeBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.eventType + .findUnique({ where: { id: safeQuery.data.id } }) + .then((data) => schemaEventTypePublic.parse(data)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.eventType + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((eventType) => schemaEventTypePublic.parse(eventType)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.eventType + .delete({ where: { id: safeQuery.data.id } }) + .then(() => res.status(200).json({ message: `EventType with id: ${safeQuery.data.id} deleted` })) + .catch((error: Error) => + res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(eventTypeById)); diff --git a/pages/api/event-types/[id]/delete.ts b/pages/api/event-types/[id]/delete.ts deleted file mode 100644 index 1009a97e05..0000000000 --- a/pages/api/event-types/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/event-types/{id}/delete: - * delete: - * summary: Remove an existing eventType - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventType to delete - * tags: - * - event-types - * responses: - * 201: - * description: OK, eventType removed successfuly - * model: EventType - * 400: - * description: Bad request. EventType id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteEventType(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.eventType.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `EventType with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `EventType with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteEventType)); diff --git a/pages/api/event-types/[id]/edit.ts b/pages/api/event-types/[id]/edit.ts deleted file mode 100644 index 785774c0b6..0000000000 --- a/pages/api/event-types/[id]/edit.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { EventTypeResponse } from "@lib/types"; -import { - schemaEventTypeBodyParams, - schemaEventTypePublic, - withValidEventType, -} from "@lib/validations/event-type"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/event-types/{id}/edit: - * patch: - * summary: Edits an existing eventType - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventType to delete - * tags: - * - event-types - * responses: - * 201: - * description: OK, eventType edited successfuly - * model: EventType - * 400: - * description: Bad request. EventType body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editEventType(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaEventTypeBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const eventType = await prisma.eventType.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaEventTypePublic.parse(eventType); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidEventType(editEventType)) -); diff --git a/pages/api/event-types/[id]/index.ts b/pages/api/event-types/[id]/index.ts deleted file mode 100644 index 645708813d..0000000000 --- a/pages/api/event-types/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { EventTypeResponse } from "@lib/types"; -import { schemaEventTypePublic } from "@lib/validations/event-type"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/event-types/{id}: - * get: - * summary: find eventType by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the eventType to get - * tags: - * - event-types - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: EventType was not found - */ -export async function eventTypeById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const eventType = await prisma.eventType.findUnique({ where: { id: safe.data.id } }); - const data = schemaEventTypePublic.parse(eventType); - - if (eventType) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "EventType was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(eventTypeById)); diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].ts new file mode 100644 index 0000000000..d78d0f1c88 --- /dev/null +++ b/pages/api/memberships/[id].ts @@ -0,0 +1,147 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { MembershipResponse } from "@lib/types"; +import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership"; +import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; + +/** + * @swagger + * /api/memberships/{userId}_{teamId}: + * get: + * summary: Get a membership by userID and teamID + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: Numeric userId of the membership to get + * - in: path + * name: teamId + * schema: + * type: integer + * required: true + * description: Numeric teamId of the membership to get + * tags: + * - memberships + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Membership was not found + * patch: + * summary: Edit an existing membership + * consumes: + * - application/json + * parameters: + * - in: body + * name: membership + * description: The membership to edit + * schema: + * type: object + * $ref: '#/components/schemas/Membership' + * required: true + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: Numeric userId of the membership to get + * - in: path + * name: teamId + * schema: + * type: integer + * required: true + * description: Numeric teamId of the membership to get + * tags: + * - memberships + * responses: + * 201: + * description: OK, membership edited successfuly + * model: Membership + * 400: + * description: Bad request. Membership body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing membership + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: Numeric userId of the membership to get + * - in: path + * name: teamId + * schema: + * type: integer + * required: true + * description: Numeric teamId of the membership to get + * tags: + * - memberships + * responses: + * 201: + * description: OK, membership removed successfuly + * model: Membership + * 400: + * description: Bad request. Membership id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function membershipById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdAsString.safeParse(query); + const safeBody = await schemaMembershipBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + // This is how we set the userId and teamId in the query for managing compoundId. + const [userId, teamId] = safeQuery.data.id.split("_"); + + switch (method) { + case "GET": + await prisma.membership + .findUnique({ where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } } }) + .then((membership) => schemaMembershipPublic.parse(membership)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Membership with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.membership + .update({ + where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } }, + data: safeBody.data, + }) + .then((membership) => schemaMembershipPublic.parse(membership)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Membership with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.membership + .delete({ where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } } }) + .then(() => + res.status(200).json({ message: `Membership with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Membership with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdString(membershipById)); diff --git a/pages/api/memberships/[id]/delete.ts b/pages/api/memberships/[id]/delete.ts deleted file mode 100644 index 8eb4e8ae4a..0000000000 --- a/pages/api/memberships/[id]/delete.ts +++ /dev/null @@ -1,55 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -/** - * @swagger - * /api/memberships/{userId}_{teamId}/delete: - * delete: - * summary: Remove an existing membership - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: Numeric ID of the user to get the membership of - * - in: path - * name: teamId - * schema: - * type: integer - * required: true - * description: Numeric ID of the team to get the membership of - * tags: - * - memberships - * responses: - * 201: - * description: OK, membership removed successfuly - * model: Membership - * 400: - * description: Bad request. Membership id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteMembership(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdAsString.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - const [userId, teamId] = safe.data.id.split("_"); - const data = await prisma.membership.delete({ - where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } }, - }); - - if (data) res.status(200).json({ message: `Membership with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Membership with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdString(deleteMembership)); diff --git a/pages/api/memberships/[id]/edit.ts b/pages/api/memberships/[id]/edit.ts deleted file mode 100644 index 66c6ccec24..0000000000 --- a/pages/api/memberships/[id]/edit.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { MembershipResponse } from "@lib/types"; -import { - schemaMembershipBodyParams, - schemaMembershipPublic, - withValidMembership, -} from "@lib/validations/membership"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -/** - * @swagger - * /api/memberships/{id}/edit: - * patch: - * summary: Edits an existing membership - * tags: - * - memberships - * responses: - * 201: - * description: OK, membership edited successfuly - * model: Membership - * 400: - * description: Bad request. Membership body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editMembership(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdAsString.safeParse(req.query); - const safeBody = await schemaMembershipBodyParams.safeParse(req.body); - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const [userId, teamId] = safeQuery.data.id.split("_"); - - const membership = await prisma.membership.update({ - where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } }, - data: safeBody.data, - }); - const data = schemaMembershipPublic.parse(membership); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")(withValidQueryIdString(withValidMembership(editMembership))); diff --git a/pages/api/memberships/[id]/index.ts b/pages/api/memberships/[id]/index.ts deleted file mode 100644 index a1505f185e..0000000000 --- a/pages/api/memberships/[id]/index.ts +++ /dev/null @@ -1,57 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { MembershipResponse } from "@lib/types"; -import { schemaMembershipPublic } from "@lib/validations/membership"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -/** - * @swagger - * /api/memberships/{userId}_{teamId}: - * get: - * summary: find membership by userID and teamID - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: Numeric userId of the membership to get - * - in: path - * name: teamId - * schema: - * type: integer - * required: true - * description: Numeric teamId of the membership to get - * tags: - * - memberships - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Membership was not found - */ -export async function membershipById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdAsString.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - const [userId, teamId] = safe.data.id.split("_"); - - const membership = await prisma.membership.findUnique({ - where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } }, - }); - const data = schemaMembershipPublic.parse(membership); - - if (membership) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Membership was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdString(membershipById)); diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].ts new file mode 100644 index 0000000000..14b106ca43 --- /dev/null +++ b/pages/api/payments/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { PaymentResponse } from "@lib/types"; +import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/payment"; +import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; + +/** + * @swagger + * /api/payments/{id}: + * get: + * summary: Get a payment by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the payment to get + * tags: + * - payments + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Payment was not found + * patch: + * summary: Edit an existing payment + * consumes: + * - application/json + * parameters: + * - in: body + * name: payment + * description: The payment to edit + * schema: + * type: object + * $ref: '#/components/schemas/Payment' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the payment to edit + * tags: + * - payments + * responses: + * 201: + * description: OK, payment edited successfuly + * model: Payment + * 400: + * description: Bad request. Payment body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing payment + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the payment to delete + * tags: + * - payments + * responses: + * 201: + * description: OK, payment removed successfuly + * model: Payment + * 400: + * description: Bad request. Payment id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function paymentById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdAsString.safeParse(query); + const safeBody = await schemaPaymentBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + const [userId, teamId] = safeQuery.data.id.split("_"); + + switch (method) { + case "GET": + await prisma.payment + .findUnique({ + where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } }, + }) + .then((payment) => schemaPaymentPublic.parse(payment)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Payment with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.payment + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((payment) => schemaPaymentPublic.parse(payment)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Payment with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.payment + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `Payment with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Payment with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdString(paymentById)); diff --git a/pages/api/payments/[id]/delete.ts b/pages/api/payments/[id]/delete.ts deleted file mode 100644 index 104fbb0da9..0000000000 --- a/pages/api/payments/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/payments/{id}/delete: - * delete: - * summary: Remove an existing payment - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the payment to delete - * tags: - * - payments - * responses: - * 201: - * description: OK, payment removed successfuly - * model: Payment - * 400: - * description: Bad request. Payment id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deletePayment(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.payment.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `Payment with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Payment with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deletePayment)); diff --git a/pages/api/payments/[id]/edit.ts b/pages/api/payments/[id]/edit.ts deleted file mode 100644 index 6b1549d66a..0000000000 --- a/pages/api/payments/[id]/edit.ts +++ /dev/null @@ -1,56 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { PaymentResponse } from "@lib/types"; -import { schemaPaymentBodyParams, schemaPaymentPublic, withValidPayment } from "@lib/validations/payment"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/payments/{id}/edit: - * patch: - * summary: Edit an existing payment - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the payment to edit - * tags: - * - payments - * responses: - * 201: - * description: OK, payment edited successfuly - * model: Payment - * 400: - * description: Bad request. Payment body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editPayment(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaPaymentBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const payment = await prisma.payment.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaPaymentPublic.parse(payment); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")(withValidQueryIdTransformParseInt(withValidPayment(editPayment))); diff --git a/pages/api/payments/[id]/index.ts b/pages/api/payments/[id]/index.ts deleted file mode 100644 index 5d4fa9547a..0000000000 --- a/pages/api/payments/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { PaymentResponse } from "@lib/types"; -import { schemaPaymentPublic } from "@lib/validations/payment"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/payments/{id}: - * get: - * summary: Get a payment by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the payment to get - * tags: - * - payments - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Payment was not found - */ -export async function paymentById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const payment = await prisma.payment.findUnique({ where: { id: safe.data.id } }); - const data = schemaPaymentPublic.parse(payment); - - if (payment) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Payment was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(paymentById)); diff --git a/pages/api/reminder-mails/[id].ts b/pages/api/reminder-mails/[id].ts new file mode 100644 index 0000000000..5d101b4c6d --- /dev/null +++ b/pages/api/reminder-mails/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { ReminderMailResponse } from "@lib/types"; +import { schemaReminderMailBodyParams, schemaReminderMailPublic } from "@lib/validations/reminder-mail"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/reminder-mails/{id}: + * get: + * summary: Get a reminderMail by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the reminderMail to get + * tags: + * - reminder-mails + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: ReminderMail was not found + * patch: + * summary: Edit an existing reminderMail + * consumes: + * - application/json + * parameters: + * - in: body + * name: reminderMail + * description: The reminderMail to edit + * schema: + * type: object + * $ref: '#/components/schemas/ReminderMail' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the reminderMail to edit + * tags: + * - reminder-mails + * responses: + * 201: + * description: OK, reminderMail edited successfuly + * model: ReminderMail + * 400: + * description: Bad request. ReminderMail body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing reminderMail + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the reminderMail to delete + * tags: + * - reminder-mails + * responses: + * 201: + * description: OK, reminderMail removed successfuly + * model: ReminderMail + * 400: + * description: Bad request. ReminderMail id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function reminderMailById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaReminderMailBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.reminderMail + .findUnique({ where: { id: safeQuery.data.id } }) + .then((data) => schemaReminderMailPublic.parse(data)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.reminderMail + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((reminderMail) => schemaReminderMailPublic.parse(reminderMail)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.reminderMail + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `ReminderMail with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(reminderMailById)); diff --git a/pages/api/reminder-mails/[id]/delete.ts b/pages/api/reminder-mails/[id]/delete.ts deleted file mode 100644 index 6b3bad4fe9..0000000000 --- a/pages/api/reminder-mails/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/reminder-mails/{id}/delete: - * delete: - * summary: Remove an existing reminder mail - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the reminderMail to delete - * tags: - * - reminder-mails - * responses: - * 201: - * description: OK, reminderMail removed successfuly - * model: ReminderMail - * 400: - * description: Bad request. ReminderMail id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteReminderMail(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.reminderMail.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `ReminderMail with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `ReminderMail with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteReminderMail)); diff --git a/pages/api/reminder-mails/[id]/edit.ts b/pages/api/reminder-mails/[id]/edit.ts deleted file mode 100644 index 2fedbb8f86..0000000000 --- a/pages/api/reminder-mails/[id]/edit.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { ReminderMailResponse } from "@lib/types"; -import { - schemaReminderMailBodyParams, - schemaReminderMailPublic, - withValidReminderMail, -} from "@lib/validations/reminder-mail"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/reminder-mails/{id}/edit: - * patch: - * summary: Edit an existing reminder mail - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the reminderMail to edit - * tags: - * - reminder-mails - * responses: - * 201: - * description: OK, reminderMail edited successfuly - * model: ReminderMail - * 400: - * description: Bad request. ReminderMail body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editReminderMail(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaReminderMailBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const reminderMail = await prisma.reminderMail.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaReminderMailPublic.parse(reminderMail); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidReminderMail(editReminderMail)) -); diff --git a/pages/api/reminder-mails/[id]/index.ts b/pages/api/reminder-mails/[id]/index.ts deleted file mode 100644 index 7b38d22cbe..0000000000 --- a/pages/api/reminder-mails/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { ReminderMailResponse } from "@lib/types"; -import { schemaReminderMailPublic } from "@lib/validations/reminder-mail"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/reminder-mails/{id}: - * get: - * summary: Get a reminder mail by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the reminderMail to get - * tags: - * - reminder-mails - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: ReminderMail was not found - */ -export async function reminderMailById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const reminderMail = await prisma.reminderMail.findUnique({ where: { id: safe.data.id } }); - const data = schemaReminderMailPublic.parse(reminderMail); - - if (reminderMail) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "ReminderMail was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(reminderMailById)); diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts new file mode 100644 index 0000000000..682dc334d2 --- /dev/null +++ b/pages/api/schedules/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { ScheduleResponse } from "@lib/types"; +import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; + +/** + * @swagger + * /api/schedules/{id}: + * get: + * summary: Get a schedule by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the schedule to get + * tags: + * - schedules + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Schedule was not found + * patch: + * summary: Edit an existing schedule + * consumes: + * - application/json + * parameters: + * - in: body + * name: schedule + * description: The schedule to edit + * schema: + * type: object + * $ref: '#/components/schemas/Schedule' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the schedule to edit + * tags: + * - schedules + * responses: + * 201: + * description: OK, schedule edited successfuly + * model: Schedule + * 400: + * description: Bad request. Schedule body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing schedule + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the schedule to delete + * tags: + * - schedules + * responses: + * 201: + * description: OK, schedule removed successfuly + * model: Schedule + * 400: + * description: Bad request. Schedule id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function scheduleById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaScheduleBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.schedule + .findUnique({ where: { id: safeQuery.data.id } }) + .then((schedule) => schemaSchedulePublic.parse(schedule)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Schedule with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.schedule + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((schedule) => schemaSchedulePublic.parse(schedule)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Schedule with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.schedule + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `Schedule with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Schedule with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(scheduleById)); diff --git a/pages/api/schedules/[id]/delete.ts b/pages/api/schedules/[id]/delete.ts deleted file mode 100644 index 4a85704a21..0000000000 --- a/pages/api/schedules/[id]/delete.ts +++ /dev/null @@ -1,43 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/schedules/{id}/delete: - * delete: - * summary: Remove an existing schedule - * tags: - * - schedules - * responses: - * 201: - * description: OK, schedule removed successfuly - * model: Schedule - * 400: - * description: Bad request. Schedule id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteSchedule(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.schedule.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `Schedule with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Schedule with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteSchedule)); diff --git a/pages/api/schedules/[id]/edit.ts b/pages/api/schedules/[id]/edit.ts deleted file mode 100644 index 97fad524a0..0000000000 --- a/pages/api/schedules/[id]/edit.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { ScheduleResponse } from "@lib/types"; -import { schemaScheduleBodyParams, schemaSchedulePublic, withValidSchedule } from "@lib/validations/schedule"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/schedules/{id}/edit: - * patch: - * summary: Edits an existing schedule - * tags: - * - schedules - * responses: - * 201: - * description: OK, schedule edited successfuly - * model: Schedule - * 400: - * description: Bad request. Schedule body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editSchedule(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaScheduleBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const schedule = await prisma.schedule.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaSchedulePublic.parse(schedule); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdTransformParseInt(withValidSchedule(editSchedule)) -); diff --git a/pages/api/schedules/[id]/index.ts b/pages/api/schedules/[id]/index.ts deleted file mode 100644 index 8bdab1fca0..0000000000 --- a/pages/api/schedules/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { ScheduleResponse } from "@lib/types"; -import { schemaSchedulePublic } from "@lib/validations/schedule"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/schedules/{id}: - * get: - * summary: Get schedule by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the schedule to delete - * tags: - * - schedules - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Schedule was not found - */ -export async function scheduleById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const schedule = await prisma.schedule.findUnique({ where: { id: safe.data.id } }); - const data = schemaSchedulePublic.parse(schedule); - - if (schedule) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Schedule was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(scheduleById)); diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts new file mode 100644 index 0000000000..f8fb8c99b2 --- /dev/null +++ b/pages/api/selected-calendars/[id].ts @@ -0,0 +1,177 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { SelectedCalendarResponse } from "@lib/types"; +import { + schemaSelectedCalendarBodyParams, + schemaSelectedCalendarPublic, +} from "@lib/validations/selected-calendar"; +import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; + +/** + * @swagger + * /api/selected-calendars/{userId}_{teamId}: + * get: + * summary: Get a selected-calendar by userID and teamID + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: Numeric userId of the selected-calendar to get + * - in: path + * name: teamId + * schema: + * type: integer + * required: true + * description: Numeric teamId of the selected-calendar to get + * tags: + * - selected-calendars + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: SelectedCalendar was not found + * patch: + * summary: Edit an existing selected-calendar + * consumes: + * - application/json + * parameters: + * - in: body + * name: selected-calendar + * description: The selected-calendar to edit + * schema: + * type: object + * $ref: '#/components/schemas/SelectedCalendar' + * required: true + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: Numeric userId of the selected-calendar to get + * - in: path + * name: teamId + * schema: + * type: integer + * required: true + * description: Numeric teamId of the selected-calendar to get + * tags: + * - selected-calendars + * responses: + * 201: + * description: OK, selected-calendar edited successfuly + * model: SelectedCalendar + * 400: + * description: Bad request. SelectedCalendar body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing selected-calendar + * parameters: + * - in: path + * name: userId + * schema: + * type: integer + * required: true + * description: Numeric userId of the selected-calendar to get + * - in: path + * name: teamId + * schema: + * type: integer + * required: true + * description: Numeric teamId of the selected-calendar to get + * tags: + * - selected-calendars + * responses: + * 201: + * description: OK, selected-calendar removed successfuly + * model: SelectedCalendar + * 400: + * description: Bad request. SelectedCalendar id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function selectedCalendarById( + req: NextApiRequest, + res: NextApiResponse +) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdAsString.safeParse(query); + const safeBody = await schemaSelectedCalendarBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + // This is how we set the userId and teamId in the query for managing compoundId. + const [userId, integration, externalId] = safeQuery.data.id.split("_"); + + switch (method) { + case "GET": + await prisma.selectedCalendar + .findUnique({ + where: { + userId_integration_externalId: { + userId: parseInt(userId), + integration: integration, + externalId: externalId, + }, + }, + }) + .then((selectedCalendar) => schemaSelectedCalendarPublic.parse(selectedCalendar)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `SelectedCalendar with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.selectedCalendar + .update({ + where: { + userId_integration_externalId: { + userId: parseInt(userId), + integration: integration, + externalId: externalId, + }, + }, + data: safeBody.data, + }) + .then((selectedCalendar) => schemaSelectedCalendarPublic.parse(selectedCalendar)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `SelectedCalendar with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.selectedCalendar + .delete({ + where: { + userId_integration_externalId: { + userId: parseInt(userId), + integration: integration, + externalId: externalId, + }, + }, + }) + .then(() => + res + .status(200) + .json({ message: `SelectedCalendar with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `SelectedCalendar with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdString(selectedCalendarById)); diff --git a/pages/api/selected-calendars/[id]/delete.ts b/pages/api/selected-calendars/[id]/delete.ts deleted file mode 100644 index ec1abebed4..0000000000 --- a/pages/api/selected-calendars/[id]/delete.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -/** - * @swagger - * /api/selected-calendars/{userId}_{teamId}/delete: - * delete: - * summary: Remove an existing record of a selected calendar - * parameters: - * - in: path - * - name: userId - * schema: - * type: integer - * required: true - * description: Numeric ID of the user to get the selected calendar of - * - name: teamId - * schema: - * type: integer - * required: true - * description: Numeric ID of the team to get the selected calendar of - * tags: - * - selected-calendars - * responses: - * 201: - * description: OK, selected calendar removed successfuly - * 400: - * description: Bad request. selected calendar id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteSelectedCalendar(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdAsString.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - const [userId, integration, externalId] = safe.data.id.split("_"); - const data = await prisma.selectedCalendar.delete({ - where: { - userId_integration_externalId: { - userId: parseInt(userId), - integration: integration, - externalId: externalId, - }, - }, - }); - - if (data) - res.status(200).json({ message: `SelectedCalendar with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `SelectedCalendar with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdString(deleteSelectedCalendar)); diff --git a/pages/api/selected-calendars/[id]/edit.ts b/pages/api/selected-calendars/[id]/edit.ts deleted file mode 100644 index c5737eb4e6..0000000000 --- a/pages/api/selected-calendars/[id]/edit.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { SelectedCalendarResponse } from "@lib/types"; -import { - schemaSelectedCalendarBodyParams, - schemaSelectedCalendarPublic, - withValidSelectedCalendar, -} from "@lib/validations/selected-calendar"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -/** - * @swagger - * /api/selected-calendars/{id}/edit: - * patch: - * summary: Edits an existing selectedCalendar - * tags: - * - selected-calendars - * responses: - * 201: - * description: OK, selectedCalendar edited successfuly - * model: SelectedCalendar - * 400: - * description: Bad request. SelectedCalendar body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editSelectedCalendar( - req: NextApiRequest, - res: NextApiResponse -) { - const safeQuery = await schemaQueryIdAsString.safeParse(req.query); - const safeBody = await schemaSelectedCalendarBodyParams.safeParse(req.body); - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const [userId, integration, externalId] = safeQuery.data.id.split("_"); - - const selectedCalendar = await prisma.selectedCalendar.update({ - where: { - userId_integration_externalId: { - userId: parseInt(userId), - integration: integration, - externalId: externalId, - }, - }, - data: safeBody.data, - }); - const data = schemaSelectedCalendarPublic.parse(selectedCalendar); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")( - withValidQueryIdString(withValidSelectedCalendar(editSelectedCalendar)) -); diff --git a/pages/api/selected-calendars/[id]/index.ts b/pages/api/selected-calendars/[id]/index.ts deleted file mode 100644 index bec8bcc600..0000000000 --- a/pages/api/selected-calendars/[id]/index.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { SelectedCalendarResponse } from "@lib/types"; -import { schemaSelectedCalendarPublic } from "@lib/validations/selected-calendar"; -import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; - -/** - * @swagger - * /api/selected-calendars/{userId}_{teamId}: - * get: - * summary: find selectedCalendar by userID and teamID - * parameters: - * - in: path - * name: userId - * schema: - * type: integer - * required: true - * description: Numeric userId of the selectedCalendar to get - * - in: path - * name: teamId - * schema: - * type: integer - * required: true - * description: Numeric teamId of the selectedCalendar to get - * tags: - * - selected-calendars - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: SelectedCalendar was not found - */ -export async function selectedCalendarById( - req: NextApiRequest, - res: NextApiResponse -) { - const safe = await schemaQueryIdAsString.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - const [userId, integration, externalId] = safe.data.id.split("_"); - - const selectedCalendar = await prisma.selectedCalendar.findUnique({ - where: { - userId_integration_externalId: { - userId: parseInt(userId), - integration: integration, - externalId: externalId, - }, - }, - }); - const data = schemaSelectedCalendarPublic.parse(selectedCalendar); - - if (selectedCalendar) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "SelectedCalendar was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdString(selectedCalendarById)); diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts new file mode 100644 index 0000000000..21defc76b8 --- /dev/null +++ b/pages/api/teams/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { TeamResponse } from "@lib/types"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; +import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team"; + +/** + * @swagger + * /api/teams/{id}: + * get: + * summary: Get a team by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the team to get + * tags: + * - teams + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: Team was not found + * patch: + * summary: Edit an existing team + * consumes: + * - application/json + * parameters: + * - in: body + * name: team + * description: The team to edit + * schema: + * type: object + * $ref: '#/components/schemas/Team' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the team to edit + * tags: + * - teams + * responses: + * 201: + * description: OK, team edited successfuly + * model: Team + * 400: + * description: Bad request. Team body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing team + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the team to delete + * tags: + * - teams + * responses: + * 201: + * description: OK, team removed successfuly + * model: Team + * 400: + * description: Bad request. Team id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function teamById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaTeamBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.team + .findUnique({ where: { id: safeQuery.data.id } }) + .then((data) => schemaTeamPublic.parse(data)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Team with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.team + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((team) => schemaTeamPublic.parse(team)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `Team with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.team + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `Team with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `Team with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(teamById)); diff --git a/pages/api/teams/[id]/delete.ts b/pages/api/teams/[id]/delete.ts deleted file mode 100644 index 0b493f3fc5..0000000000 --- a/pages/api/teams/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/teams/{id}/delete: - * delete: - * summary: Remove an existing team - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the team to remove - * tags: - * - teams - * responses: - * 201: - * description: OK, team removed successfuly - * model: Team - * 400: - * description: Bad request. Team id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteTeam(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.team.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `Team with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `Team with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteTeam)); diff --git a/pages/api/teams/[id]/edit.ts b/pages/api/teams/[id]/edit.ts deleted file mode 100644 index 9791e37046..0000000000 --- a/pages/api/teams/[id]/edit.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { TeamResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; -import { schemaTeamBodyParams, schemaTeamPublic, withValidTeam } from "@lib/validations/team"; - -/** - * @swagger - * /api/teams/{id}/edit: - * patch: - * summary: Edits an existing team - * consumes: - * - application/json - * parameters: - * - in: body - * name: team - * description: The team to edit - * schema: Team - * required: true - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the team to edit - * tags: - * - teams - * responses: - * 201: - * description: OK, team edited successfuly - * model: Team - * 400: - * description: Bad request. Team body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editTeam(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaTeamBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const team = await prisma.team.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaTeamPublic.parse(team); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")(withValidQueryIdTransformParseInt(withValidTeam(editTeam))); diff --git a/pages/api/teams/[id]/index.ts b/pages/api/teams/[id]/index.ts deleted file mode 100644 index 62765e544d..0000000000 --- a/pages/api/teams/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { TeamResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; -import { schemaTeamPublic } from "@lib/validations/team"; - -/** - * @swagger - * /api/teams/{id}: - * get: - * summary: find team by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the team to get - * tags: - * - teams - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: Team was not found - */ -export async function teamById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const team = await prisma.team.findUnique({ where: { id: safe.data.id } }); - const data = schemaTeamPublic.parse(team); - - if (team) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "Team was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(teamById)); diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts new file mode 100644 index 0000000000..fa0b4c7255 --- /dev/null +++ b/pages/api/users/[id].ts @@ -0,0 +1,130 @@ +import type { NextApiRequest, NextApiResponse } from "next"; + +import prisma from "@calcom/prisma"; + +import { withMiddleware } from "@lib/helpers/withMiddleware"; +import type { UserResponse } from "@lib/types"; +import { + schemaQueryIdParseInt, + withValidQueryIdTransformParseInt, +} from "@lib/validations/shared/queryIdTransformParseInt"; +import { schemaUserBodyParams, schemaUserPublic } from "@lib/validations/user"; + +/** + * @swagger + * /api/users/{id}: + * get: + * summary: Get a user by ID + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the user to get + * tags: + * - users + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: User was not found + * patch: + * summary: Edit an existing user + * consumes: + * - application/json + * parameters: + * - in: body + * name: user + * description: The user to edit + * schema: + * type: object + * $ref: '#/components/schemas/User' + * required: true + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the user to edit + * tags: + * - users + * responses: + * 201: + * description: OK, user edited successfuly + * model: User + * 400: + * description: Bad request. User body is invalid. + * 401: + * description: Authorization information is missing or invalid. + * delete: + * summary: Remove an existing user + * parameters: + * - in: path + * name: id + * schema: + * type: integer + * required: true + * description: Numeric ID of the user to delete + * tags: + * - users + * responses: + * 201: + * description: OK, user removed successfuly + * model: User + * 400: + * description: Bad request. User id is invalid. + * 401: + * description: Authorization information is missing or invalid. + */ +export async function userById(req: NextApiRequest, res: NextApiResponse) { + const { method, query, body } = req; + const safeQuery = await schemaQueryIdParseInt.safeParse(query); + const safeBody = await schemaUserBodyParams.safeParse(body); + if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); + + switch (method) { + case "GET": + await prisma.user + .findUnique({ where: { id: safeQuery.data.id } }) + .then((user) => schemaUserPublic.parse(user)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `User with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "PATCH": + if (!safeBody.success) throw new Error("Invalid request body"); + await prisma.user + .update({ + where: { id: safeQuery.data.id }, + data: safeBody.data, + }) + .then((user) => schemaUserPublic.parse(user)) + .then((data) => res.status(200).json({ data })) + .catch((error: Error) => + res.status(404).json({ message: `User with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + case "DELETE": + await prisma.user + .delete({ where: { id: safeQuery.data.id } }) + .then(() => + res.status(200).json({ message: `User with id: ${safeQuery.data.id} deleted successfully` }) + ) + .catch((error: Error) => + res.status(404).json({ message: `User with id: ${safeQuery.data.id} not found`, error }) + ); + break; + + default: + res.status(405).json({ message: "Method not allowed" }); + break; + } +} + +export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(userById)); diff --git a/pages/api/users/[id]/delete.ts b/pages/api/users/[id]/delete.ts deleted file mode 100644 index b484d2cae5..0000000000 --- a/pages/api/users/[id]/delete.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { BaseResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; - -/** - * @swagger - * /api/users/{id}/delete: - * delete: - * summary: Remove an existing user - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the user to delete - * tags: - * - users - * responses: - * 201: - * description: OK, user removed successfuly - * model: User - * 400: - * description: Bad request. User id is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function deleteUser(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query", safe.error); - - const data = await prisma.user.delete({ where: { id: safe.data.id } }); - - if (data) res.status(200).json({ message: `User with id: ${safe.data.id} deleted successfully` }); - else - (error: Error) => - res.status(400).json({ - message: `User with id: ${safe.data.id} was not able to be processed`, - error, - }); -} - -export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteUser)); diff --git a/pages/api/users/[id]/edit.ts b/pages/api/users/[id]/edit.ts deleted file mode 100644 index 7ebf00517e..0000000000 --- a/pages/api/users/[id]/edit.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { UserResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; -import { schemaUserBodyParams, schemaUserPublic, withValidUser } from "@lib/validations/user"; - -/** - * @swagger - * /api/users/{id}/edit: - * patch: - * summary: Edit an existing user - * consumes: - * - application/json - * parameters: - * - in: body - * name: user - * description: The user to edit - * schema: - * type: object - * $ref: '#/components/schemas/User' - * required: true - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the user to edit - * tags: - * - users - * responses: - * 201: - * description: OK, user edited successfuly - * model: User - * 400: - * description: Bad request. User body is invalid. - * 401: - * description: Authorization information is missing or invalid. - */ -export async function editUser(req: NextApiRequest, res: NextApiResponse) { - const safeQuery = await schemaQueryIdParseInt.safeParse(req.query); - const safeBody = await schemaUserBodyParams.safeParse(req.body); - - if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request"); - const user = await prisma.user.update({ - where: { id: safeQuery.data.id }, - data: safeBody.data, - }); - const data = schemaUserPublic.parse(user); - - if (data) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, - error, - }); -} - -export default withMiddleware("HTTP_PATCH")(withValidQueryIdTransformParseInt(withValidUser(editUser))); diff --git a/pages/api/users/[id]/index.ts b/pages/api/users/[id]/index.ts deleted file mode 100644 index c9ef417223..0000000000 --- a/pages/api/users/[id]/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; - -import prisma from "@calcom/prisma"; - -import { withMiddleware } from "@lib/helpers/withMiddleware"; -import type { UserResponse } from "@lib/types"; -import { - schemaQueryIdParseInt, - withValidQueryIdTransformParseInt, -} from "@lib/validations/shared/queryIdTransformParseInt"; -import { schemaUserPublic } from "@lib/validations/user"; - -/** - * @swagger - * /api/users/{id}: - * get: - * summary: Get a user by ID - * parameters: - * - in: path - * name: id - * schema: - * type: integer - * required: true - * description: Numeric ID of the user to get - * tags: - * - users - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: User was not found - */ -export async function userById(req: NextApiRequest, res: NextApiResponse) { - const safe = await schemaQueryIdParseInt.safeParse(req.query); - if (!safe.success) throw new Error("Invalid request query"); - - const user = await prisma.user.findUnique({ where: { id: safe.data.id } }); - const data = schemaUserPublic.parse(user); - - if (user) res.status(200).json({ data }); - else - (error: Error) => - res.status(404).json({ - message: "User was not found", - error, - }); -} - -export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(userById)); diff --git a/prettier.rc.js b/prettier.rc.js deleted file mode 100644 index aa497c0ac5..0000000000 --- a/prettier.rc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - semi: false, - singleQuote: true, - arrowParens: "avoid", - trailingComma: "none", - endOfLine: "auto", -};