Merge pull request #29 from calcom/fix/users-and-teams-id

This commit is contained in:
Agusti Fernandez
2022-04-04 21:40:59 +02:00
committed by GitHub
79 changed files with 2259 additions and 3045 deletions
+1
View File
@@ -0,0 +1 @@
module.exports = require("@calcom/config/eslint-preset");
-17
View File
@@ -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/*"]
}
+2 -1
View File
@@ -1,4 +1,5 @@
.next/
coverage/
node_modules/
tests/
tests/
templates/
+1
View File
@@ -0,0 +1 @@
module.exports = require("../../packages/config/prettier-preset");
+58 -256
View File
@@ -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"
}
}
}
}
+12
View File
@@ -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"]);
+2 -1
View File
@@ -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,
-24
View File
@@ -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<ResponseData>) {
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));
-38
View File
@@ -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<ResponseData>) {
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)));
-24
View File
@@ -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<ResponseData>) {
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));
-20
View File
@@ -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<ResponseData>) {
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);
-24
View File
@@ -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<ResponseData>) {
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));
+130
View File
@@ -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<AttendeeResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-58
View File
@@ -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<AttendeeResponse>) {
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))
);
-51
View File
@@ -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<AttendeeResponse>) {
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));
+130
View File
@@ -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<AvailabilityResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-62
View File
@@ -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<AvailabilityResponse>) {
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))
);
-51
View File
@@ -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<AvailabilityResponse>) {
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));
+138
View File
@@ -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<BookingReferenceResponse>
) {
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)
);
@@ -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<BaseResponse>) {
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));
-65
View File
@@ -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<BookingReferenceResponse>
) {
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))
);
@@ -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<BookingReferenceResponse>
) {
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));
+130
View File
@@ -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<BookingResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-56
View File
@@ -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<BookingResponse>) {
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)));
-51
View File
@@ -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<BookingResponse>) {
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));
+130
View File
@@ -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<CredentialResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-62
View File
@@ -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<CredentialResponse>) {
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))
);
-51
View File
@@ -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<CredentialResponse>) {
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));
+144
View File
@@ -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<DailyEventReferenceResponse>
) {
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)
);
@@ -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<BaseResponse>) {
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));
@@ -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<DailyEventReferenceResponse>
) {
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))
);
@@ -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<DailyEventReferenceResponse>
) {
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));
+144
View File
@@ -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<DestinationCalendarResponse>
) {
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)
);
@@ -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<BaseResponse>) {
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));
@@ -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<DestinationCalendarResponse>
) {
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))
);
@@ -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<DestinationCalendarResponse>
) {
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));
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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
+133
View File
@@ -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<EventTypeCustomInputResponse>) {
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));
@@ -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<BaseResponse>) {
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));
@@ -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<EventTypeCustomInputResponse>
) {
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))
);
@@ -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<EventTypeCustomInputResponse>
) {
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));
+128
View File
@@ -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<EventTypeResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-62
View File
@@ -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<EventTypeResponse>) {
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))
);
-51
View File
@@ -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<EventTypeResponse>) {
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));
+147
View File
@@ -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<MembershipResponse>) {
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));
-55
View File
@@ -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<BaseResponse>) {
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));
-51
View File
@@ -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<MembershipResponse>) {
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)));
-57
View File
@@ -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<MembershipResponse>) {
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));
+130
View File
@@ -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<PaymentResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-56
View File
@@ -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<PaymentResponse>) {
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)));
-51
View File
@@ -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<PaymentResponse>) {
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));
+130
View File
@@ -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<ReminderMailResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-62
View File
@@ -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<ReminderMailResponse>) {
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))
);
-51
View File
@@ -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<ReminderMailResponse>) {
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));
+130
View File
@@ -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<ScheduleResponse>) {
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));
-43
View File
@@ -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<BaseResponse>) {
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));
-51
View File
@@ -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<ScheduleResponse>) {
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))
);
-51
View File
@@ -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<ScheduleResponse>) {
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));
+177
View File
@@ -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<SelectedCalendarResponse>
) {
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));
@@ -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<BaseResponse>) {
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));
-62
View File
@@ -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<SelectedCalendarResponse>
) {
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))
);
@@ -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<SelectedCalendarResponse>
) {
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));
+130
View File
@@ -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<TeamResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-63
View File
@@ -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<TeamResponse>) {
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)));
-51
View File
@@ -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<TeamResponse>) {
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));
+130
View File
@@ -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<UserResponse>) {
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));
-50
View File
@@ -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<BaseResponse>) {
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));
-65
View File
@@ -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<UserResponse>) {
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)));
-51
View File
@@ -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<UserResponse>) {
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));
-7
View File
@@ -1,7 +0,0 @@
module.exports = {
semi: false,
singleQuote: true,
arrowParens: "avoid",
trailingComma: "none",
endOfLine: "auto",
};