mvoe to less files
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
.next/
|
||||
coverage/
|
||||
node_modules/
|
||||
tests/
|
||||
tests/
|
||||
templates/
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require("../../packages/config/prettier-preset");
|
||||
@@ -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));
|
||||
@@ -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)));
|
||||
@@ -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));
|
||||
@@ -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);
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
);
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
);
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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)));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
);
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
);
|
||||
@@ -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));
|
||||
@@ -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 {
|
||||
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
|
||||
* 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 schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaPaymentBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.payment
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.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")(withValidQueryIdTransformParseInt(paymentById));
|
||||
@@ -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));
|
||||
@@ -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)));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
);
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
@@ -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))
|
||||
);
|
||||
@@ -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));
|
||||
@@ -90,7 +90,7 @@ export async function teamById(req: NextApiRequest, res: NextApiResponse<TeamRes
|
||||
await prisma.team
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaTeamPublic.parse(data))
|
||||
.then((data: TeamResponse) => res.status(200).json({ 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 })
|
||||
);
|
||||
@@ -104,7 +104,7 @@ export async function teamById(req: NextApiRequest, res: NextApiResponse<TeamRes
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((team) => schemaTeamPublic.parse(team))
|
||||
.then((data: TeamResponse) => res.status(200).json({ 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 })
|
||||
);
|
||||
|
||||
@@ -89,8 +89,8 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
|
||||
case "GET":
|
||||
await prisma.user
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data: UserResponse) => schemaUserPublic.parse(data))
|
||||
.then((data: UserResponse) => res.status(200).json({ 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 })
|
||||
);
|
||||
@@ -104,7 +104,7 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((user) => schemaUserPublic.parse(user))
|
||||
.then((data: UserResponse) => res.status(200).json({ data }))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `User with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
module.exports = {
|
||||
semi: false,
|
||||
singleQuote: true,
|
||||
arrowParens: "avoid",
|
||||
trailingComma: "none",
|
||||
endOfLine: "auto",
|
||||
};
|
||||
Reference in New Issue
Block a user