prettier
This commit is contained in:
1 parent
39ae2aed37
commit
1de7bc4146
126 files changed
+1240
-992
No files matched your search
@@ -1,7 +1,7 @@
|
||||
|
||||
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";
|
||||
|
||||
@@ -13,8 +13,7 @@ type ResponseData = {
|
||||
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 } })
|
||||
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.
|
||||
@@ -22,8 +21,4 @@ export async function deleteApiKey(req: NextApiRequest, res: NextApiResponse<Res
|
||||
}
|
||||
}
|
||||
|
||||
export default withMiddleware("deleteOnly", "addRequestId")(
|
||||
withValidQueryIdString(
|
||||
deleteApiKey
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_DELETE", "addRequestId")(withValidQueryIdString(deleteApiKey));
|
||||
@@ -1,10 +1,10 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaApiKey, withValidApiKey } from "@lib/validations/apiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/apiKey";
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -14,23 +14,25 @@ type ResponseData = {
|
||||
};
|
||||
|
||||
export async function editApiKey(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, body, method } = req;
|
||||
const { query, body } = req;
|
||||
const safeQuery = await schemaQueryIdAsString.safeParse(query);
|
||||
const safeBody = await schemaApiKey.safeParse(body);
|
||||
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,
|
||||
})
|
||||
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 })
|
||||
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("patchOnly","addRequestId")(
|
||||
withValidQueryIdString(
|
||||
withValidApiKey(
|
||||
editApiKey)
|
||||
)
|
||||
);
|
||||
export default withMiddleware(
|
||||
"HTTP_PATCH",
|
||||
"addRequestId"
|
||||
)(withValidQueryIdString(withValidApiKey(editApiKey)));
|
||||
@@ -1,14 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
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;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
};
|
||||
|
||||
@@ -18,13 +17,8 @@ export async function apiKeyById(req: NextApiRequest, res: NextApiResponse<Respo
|
||||
const data = await prisma.apiKey.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: "ApiKey was not found" });
|
||||
else res.status(404).json({ error: { message: "ApiKey was not found" } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(
|
||||
withValidQueryIdString(
|
||||
apiKeyById
|
||||
)
|
||||
);
|
||||
export default withMiddleware("addRequestId", "HTTP_GET")(withValidQueryIdString(apiKeyById));
|
||||
@@ -1,9 +1,10 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
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;
|
||||
@@ -16,4 +17,4 @@ async function allApiKeys(req: NextApiRequest, res: NextApiResponse<ResponseData
|
||||
else res.status(400).json({ error: "No data found" });
|
||||
}
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(allApiKeys);
|
||||
export default withMiddleware("addRequestId", "HTTP_GET")(allApiKeys);
|
||||
@@ -2,27 +2,23 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaApiKey, withValidApiKey } from "@lib/validations/apiKey";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/apiKey";
|
||||
|
||||
type ResponseData = {
|
||||
data?: ApiKey;
|
||||
error?: object;
|
||||
error?: unknown;
|
||||
};
|
||||
|
||||
async function createApiKey(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = schemaApiKey.safeParse(req.body);
|
||||
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: error } });
|
||||
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","postOnly")(
|
||||
withValidApiKey(
|
||||
createApiKey
|
||||
)
|
||||
);
|
||||
export default withMiddleware("addRequestId", "HTTP_POST")(withValidApiKey(createApiKey));
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,11 @@ export async function attendee(req: NextApiRequest, res: NextApiResponse<Respons
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const attendee = await prisma.attendee
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const attendee = await prisma.attendee.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the attendee type from the database if there's an existing resource.
|
||||
if (attendee) res.status(200).json({ message: `attendee with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.attendee.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAttendee, withValidAttendee } from "@lib/validations/attendee";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Attendee;
|
||||
@@ -18,16 +21,21 @@ export async function editAttendee(req: NextApiRequest, res: NextApiResponse<Res
|
||||
const safeBody = await schemaAttendee.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
await prisma.attendee.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(attendee => {
|
||||
res.status(200).json({ data: attendee });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
});
|
||||
await prisma.attendee
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((attendee) => {
|
||||
res.status(200).json({ data: attendee });
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating attendees" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating attendees" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidAttendee(editAttendee));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Attendee;
|
||||
@@ -14,7 +17,7 @@ type ResponseData = {
|
||||
export async function attendee(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
|
||||
if (method === "GET" && safe.success) {
|
||||
const attendee = await prisma.attendee.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Attendee[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAttendee, withValidAttendee } from "@lib/validations/attendee";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -14,13 +14,13 @@ type ResponseData = {
|
||||
async function createAttendee(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { body, method } = req;
|
||||
const safe = schemaAttendee.safeParse(body);
|
||||
|
||||
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.attendee
|
||||
.create({ data: safe.data })
|
||||
.then((attendee) => res.status(201).json({ data: attendee }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create attendee type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.attendee
|
||||
.create({ data: safe.data })
|
||||
.then((attendee) => res.status(201).json({ data: attendee }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create attendee type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -13,12 +16,12 @@ export async function availability(req: NextApiRequest, res: NextApiResponse<Res
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const availability = await prisma.availability
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const availability = await prisma.availability.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the availability type from the database if there's an existing resource.
|
||||
if (availability) res.status(200).json({ message: `availability with id: ${safe.data.id} deleted successfully` });
|
||||
if (availability)
|
||||
res.status(200).json({ message: `availability with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.availability.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaAvailability, withValidAvailability,} from "@lib/validations/availability";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAvailability, withValidAvailability } from "@lib/validations/availability";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Availability;
|
||||
@@ -18,16 +21,21 @@ export async function editAvailability(req: NextApiRequest, res: NextApiResponse
|
||||
const safeBody = await schemaAvailability.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
await prisma.availability.update({
|
||||
await prisma.availability
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(availability => {
|
||||
})
|
||||
.then((availability) => {
|
||||
res.status(200).json({ data: availability });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
// Reject any other HTTP method than PATCH
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating availabilities" });
|
||||
// Reject any other HTTP method than PATCH
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating availabilities" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidAvailability(editAvailability));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Availability;
|
||||
@@ -14,7 +17,7 @@ type ResponseData = {
|
||||
export async function availability(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
|
||||
if (method === "GET" && safe.success) {
|
||||
const availability = await prisma.availability.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
@@ -24,5 +27,4 @@ export async function availability(req: NextApiRequest, res: NextApiResponse<Res
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(availability);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Availability[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAvailability, withValidAvailability } from "@lib/validations/availability";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -19,7 +19,9 @@ async function createAvailability(req: NextApiRequest, res: NextApiResponse<Resp
|
||||
await prisma.availability
|
||||
.create({ data: safe.data })
|
||||
.then((availability) => res.status(201).json({ data: availability }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create availability type", error: error }));
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create availability type", error: error })
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteBookingReference(req: NextApiRequest, res: NextApiRe
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const bookingReference = await prisma.bookingReference
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const bookingReference = await prisma.bookingReference.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the bookingReference type from the database if there's an existing resource.
|
||||
if (bookingReference) res.status(200).json({ message: `bookingReference with id: ${safe.data.id} deleted successfully` });
|
||||
if (bookingReference)
|
||||
res.status(200).json({ message: `bookingReference with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.bookingReference.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBookingReference, withValidBookingReference } from "@lib/validations/booking-reference";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: BookingReference;
|
||||
@@ -18,15 +21,18 @@ export async function editBookingReference(req: NextApiRequest, res: NextApiResp
|
||||
const safeBody = await schemaBookingReference.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.bookingReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.bookingReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated` })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated` });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating bookingReferences" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating bookingReferences" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidBookingReference(editBookingReference));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: BookingReference;
|
||||
@@ -23,5 +26,4 @@ export async function bookingReference(req: NextApiRequest, res: NextApiResponse
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(bookingReference);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: BookingReference[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBookingReference, withValidBookingReference } from "@lib/validations/booking-reference";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,13 @@ async function createBookingReference(req: NextApiRequest, res: NextApiResponse<
|
||||
const { body, method } = req;
|
||||
const safe = schemaBookingReference.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.bookingReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create bookingReference type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.bookingReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create bookingReference type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,14 +16,14 @@ export async function deleteBooking(req: NextApiRequest, res: NextApiResponse<Re
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const booking = await prisma.booking
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const booking = await prisma.booking.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the booking type from the database if there's an existing resource.
|
||||
if (booking) res.status(200).json({ message: `booking with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.booking.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
} else
|
||||
res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(deleteBooking);
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBooking, withValidBooking } from "@lib/validations/booking";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Booking;
|
||||
@@ -19,18 +22,23 @@ export async function editBooking(req: NextApiRequest, res: NextApiResponse<Resp
|
||||
|
||||
if (method === "PATCH") {
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
await prisma.booking.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(booking => {
|
||||
res.status(200).json({ data: booking });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
});
|
||||
await prisma.booking
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((booking) => {
|
||||
res.status(200).json({ data: booking });
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating bookings" });
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating bookings" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Booking;
|
||||
@@ -26,5 +29,4 @@ export async function booking(req: NextApiRequest, res: NextApiResponse<Response
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(booking);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Booking[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBooking, withValidBooking } from "@lib/validations/booking";
|
||||
|
||||
type ResponseData = {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteCredential(req: NextApiRequest, res: NextApiResponse
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const credential = await prisma.credential
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const credential = await prisma.credential.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the credential type from the database if there's an existing resource.
|
||||
if (credential) res.status(200).json({ message: `credential with id: ${safe.data.id} deleted successfully` });
|
||||
if (credential)
|
||||
res.status(200).json({ message: `credential with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.credential.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaCredential, withValidCredential } from "@lib/validations/credential";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Credential;
|
||||
@@ -18,15 +21,18 @@ export async function editCredential(req: NextApiRequest, res: NextApiResponse<R
|
||||
const safeBody = await schemaCredential.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.credential.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.credential.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating credentials" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating credentials" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidCredential(editCredential));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Credential;
|
||||
@@ -23,5 +26,4 @@ export async function credential(req: NextApiRequest, res: NextApiResponse<Respo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(credential);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Credential[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaCredential, withValidCredential } from "@lib/validations/credential";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,11 @@ async function createCredential(req: NextApiRequest, res: NextApiResponse<Respon
|
||||
const { body, method } = req;
|
||||
const safe = schemaCredential.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.credential
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create credential type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.credential
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create credential type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,19 +16,17 @@ type ResponseData = {
|
||||
export async function deleteDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const deletedDailyEventReference = await prisma.dailyEventReference
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const deletedDailyEventReference = await prisma.dailyEventReference.delete({
|
||||
where: { id: safe.data.id },
|
||||
});
|
||||
// We only remove the dailyEventReference type from the database if there's an existing resource.
|
||||
if (deletedDailyEventReference) res.status(200).json({ message: `dailyEventReference with id: ${safe.data.id} deleted successfully` });
|
||||
if (deletedDailyEventReference)
|
||||
res.status(200).json({ message: `dailyEventReference with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.dailyEventReference.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
// export default withValidQueryIdTransformParseInt(deleteDailyEventReference);
|
||||
export default withMiddleware("deleteOnly")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
deleteDailyEventReference
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteDailyEventReference));
|
||||
@@ -1,10 +1,16 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDailyEventReference, withValidDailyEventReference } from "@lib/validations/daily-event-reference";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDailyEventReference,
|
||||
withValidDailyEventReference,
|
||||
} from "@lib/validations/daily-event-reference";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference;
|
||||
@@ -18,15 +24,18 @@ export async function editDailyEventReference(req: NextApiRequest, res: NextApiR
|
||||
const safeBody = await schemaDailyEventReference.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.dailyEventReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.dailyEventReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating dailyEventReferences" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating dailyEventReferences" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidDailyEventReference(editDailyEventReference));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference;
|
||||
@@ -23,5 +26,4 @@ export async function dailyEventReference(req: NextApiRequest, res: NextApiRespo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(dailyEventReference);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDailyEventReference, withValidDailyEventReference } from "@lib/validations/daily-event-reference";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDailyEventReference,
|
||||
withValidDailyEventReference,
|
||||
} from "@lib/validations/daily-event-reference";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference;
|
||||
@@ -15,11 +18,13 @@ async function createDailyEventReference(req: NextApiRequest, res: NextApiRespon
|
||||
const { body, method } = req;
|
||||
const safe = schemaDailyEventReference.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.dailyEventReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create dailyEventReference type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.dailyEventReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create dailyEventReference type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteDestinationCalendar(req: NextApiRequest, res: NextAp
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const destinationCalendar = await prisma.destinationCalendar
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const destinationCalendar = await prisma.destinationCalendar.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the destinationCalendar type from the database if there's an existing resource.
|
||||
if (destinationCalendar) res.status(200).json({ message: `destinationCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
if (destinationCalendar)
|
||||
res.status(200).json({ message: `destinationCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.destinationCalendar.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDestinationCalendar, withValidDestinationCalendar } from "@lib/validations/destination-calendar";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDestinationCalendar,
|
||||
withValidDestinationCalendar,
|
||||
} from "@lib/validations/destination-calendar";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar;
|
||||
@@ -18,15 +24,18 @@ export async function editDestinationCalendar(req: NextApiRequest, res: NextApiR
|
||||
const safeBody = await schemaDestinationCalendar.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.destinationCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.destinationCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating destinationCalendars" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating destinationCalendars" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidDestinationCalendar(editDestinationCalendar));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar;
|
||||
@@ -23,5 +26,4 @@ export async function destinationCalendar(req: NextApiRequest, res: NextApiRespo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(destinationCalendar);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDestinationCalendar, withValidDestinationCalendar } from "@lib/validations/destination-calendar";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDestinationCalendar,
|
||||
withValidDestinationCalendar,
|
||||
} from "@lib/validations/destination-calendar";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar;
|
||||
@@ -15,11 +18,13 @@ async function createDestinationCalendar(req: NextApiRequest, res: NextApiRespon
|
||||
const { body, method } = req;
|
||||
const safe = schemaDestinationCalendar.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.destinationCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create destinationCalendar type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.destinationCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create destinationCalendar type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteEventTypeCustomInput(req: NextApiRequest, res: NextA
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const eventTypeCustomInput = await prisma.eventTypeCustomInput
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const eventTypeCustomInput = await prisma.eventTypeCustomInput.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the eventTypeCustomInput type from the database if there's an existing resource.
|
||||
if (eventTypeCustomInput) res.status(200).json({ message: `eventTypeCustomInput with id: ${safe.data.id} deleted successfully` });
|
||||
if (eventTypeCustomInput)
|
||||
res.status(200).json({ message: `eventTypeCustomInput with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.eventTypeCustomInput.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaEventTypeCustomInput, withValidEventTypeCustomInput } from "@lib/validations/eventTypeCustomInput";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaEventTypeCustomInput,
|
||||
withValidEventTypeCustomInput,
|
||||
} from "@lib/validations/eventTypeCustomInput";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput;
|
||||
@@ -18,15 +24,18 @@ export async function editEventTypeCustomInput(req: NextApiRequest, res: NextApi
|
||||
const safeBody = await schemaEventTypeCustomInput.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.eventTypeCustomInput.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.eventTypeCustomInput.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating eventTypeCustomInputs" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating eventTypeCustomInputs" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidEventTypeCustomInput(editEventTypeCustomInput));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput;
|
||||
@@ -23,5 +26,4 @@ export async function eventTypeCustomInput(req: NextApiRequest, res: NextApiResp
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(eventTypeCustomInput);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaEventTypeCustomInput, withValidEventTypeCustomInput } from "@lib/validations/eventTypeCustomInput";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaEventTypeCustomInput,
|
||||
withValidEventTypeCustomInput,
|
||||
} from "@lib/validations/eventTypeCustomInput";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput;
|
||||
@@ -15,11 +18,13 @@ async function createEventTypeCustomInput(req: NextApiRequest, res: NextApiRespo
|
||||
const { body, method } = req;
|
||||
const safe = schemaEventTypeCustomInput.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.eventTypeCustomInput
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create eventTypeCustomInput type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.eventTypeCustomInput
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create eventTypeCustomInput type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,14 +16,15 @@ export async function deleteEventType(req: NextApiRequest, res: NextApiResponse<
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const eventType = await prisma.eventType
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const eventType = await prisma.eventType.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the eventType type from the database if there's an existing resource.
|
||||
if (eventType) res.status(200).json({ message: `eventType with id: ${safe.data.id} deleted successfully` });
|
||||
if (eventType)
|
||||
res.status(200).json({ message: `eventType with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.eventType.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
} else
|
||||
res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(deleteEventType);
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaEventType, withValidEventType } from "@lib/validations/eventType";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventType;
|
||||
@@ -19,18 +22,23 @@ export async function editEventType(req: NextApiRequest, res: NextApiResponse<Re
|
||||
|
||||
if (method === "PATCH") {
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
await prisma.eventType.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(event => {
|
||||
res.status(200).json({ data: event });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
});
|
||||
await prisma.eventType
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((event) => {
|
||||
res.status(200).json({ data: event });
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating event-types" });
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating event-types" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventType;
|
||||
@@ -26,5 +29,4 @@ export async function eventType(req: NextApiRequest, res: NextApiResponse<Respon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(eventType);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventType[];
|
||||
message?: string;
|
||||
@@ -15,7 +15,7 @@ export default async function eventType(req: NextApiRequest, res: NextApiRespons
|
||||
const data = await prisma.eventType.findMany();
|
||||
res.status(200).json({ data });
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaEventType, withValidEventType } from "@lib/validations/eventType";
|
||||
|
||||
type ResponseData = {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteMembership(req: NextApiRequest, res: NextApiResponse
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const membership = await prisma.membership
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const membership = await prisma.membership.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the membership type from the database if there's an existing resource.
|
||||
if (membership) res.status(200).json({ message: `membership with id: ${safe.data.id} deleted successfully` });
|
||||
if (membership)
|
||||
res.status(200).json({ message: `membership with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.membership.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaMembership, withValidMembership } from "@lib/validations/membership";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Membership;
|
||||
@@ -18,15 +21,18 @@ export async function editMembership(req: NextApiRequest, res: NextApiResponse<R
|
||||
const safeBody = await schemaMembership.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.membership.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.membership.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating memberships" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating memberships" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidMembership(editMembership));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Membership;
|
||||
@@ -23,5 +26,4 @@ export async function membership(req: NextApiRequest, res: NextApiResponse<Respo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(membership);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Membership[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaMembership, withValidMembership } from "@lib/validations/membership";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,11 @@ async function createMembership(req: NextApiRequest, res: NextApiResponse<Respon
|
||||
const { body, method } = req;
|
||||
const safe = schemaMembership.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.membership
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create membership type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.membership
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create membership type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,11 @@ export async function deleteSchedule(req: NextApiRequest, res: NextApiResponse<R
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const schedule = await prisma.schedule
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const schedule = await prisma.schedule.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the schedule type from the database if there's an existing resource.
|
||||
if (schedule) res.status(200).json({ message: `schedule with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.schedule.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSchedule, withValidSchedule } from "@lib/validations/schedule";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Schedule;
|
||||
@@ -18,15 +21,18 @@ export async function editSchedule(req: NextApiRequest, res: NextApiResponse<Res
|
||||
const safeBody = await schemaSchedule.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.schedule.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.schedule.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating schedules" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating schedules" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidSchedule(editSchedule));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Schedule;
|
||||
@@ -23,5 +26,4 @@ export async function schedule(req: NextApiRequest, res: NextApiResponse<Respons
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(schedule);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Schedule[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSchedule, withValidSchedule } from "@lib/validations/schedule";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,11 @@ async function createSchedule(req: NextApiRequest, res: NextApiResponse<Response
|
||||
const { body, method } = req;
|
||||
const safe = schemaSchedule.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.schedule
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create schedule type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.schedule
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create schedule type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteSelectedCalendar(req: NextApiRequest, res: NextApiRe
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const selectedCalendar = await prisma.selectedCalendar
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const selectedCalendar = await prisma.selectedCalendar.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the selectedCalendar type from the database if there's an existing resource.
|
||||
if (selectedCalendar) res.status(200).json({ message: `selectedCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
if (selectedCalendar)
|
||||
res.status(200).json({ message: `selectedCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.selectedCalendar.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSelectedCalendar, withValidSelectedCalendar } from "@lib/validations/selected-calendar";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: SelectedCalendar;
|
||||
@@ -18,15 +21,18 @@ export async function editSelectedCalendar(req: NextApiRequest, res: NextApiResp
|
||||
const safeBody = await schemaSelectedCalendar.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.selectedCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.selectedCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating selectedCalendars" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating selectedCalendars" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidSelectedCalendar(editSelectedCalendar));
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: SelectedCalendar;
|
||||
@@ -23,5 +26,4 @@ export async function selectedCalendar(req: NextApiRequest, res: NextApiResponse
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(selectedCalendar);
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: SelectedCalendar[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSelectedCalendar, withValidSelectedCalendar } from "@lib/validations/selected-calendar";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,13 @@ async function createSelectedCalendar(req: NextApiRequest, res: NextApiResponse<
|
||||
const { body, method } = req;
|
||||
const safe = schemaSelectedCalendar.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.selectedCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create selectedCalendar type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.selectedCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create selectedCalendar type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
message: string;
|
||||
error?: object;
|
||||
};
|
||||
|
||||
export async function deleteTeam(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const data = await prisma.team
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
// We only remove the team type from the database if there's an existing resource.
|
||||
if (data) res.status(200).json({ message: `Team with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.team.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Team with id: ${safe.data.id} was not able to be processed` });
|
||||
}
|
||||
if (!safe.success) throw new Error("Invalid request query");
|
||||
|
||||
const data = await prisma.team.delete({ where: { id: safe.data.id } });
|
||||
|
||||
if (data) res.status(200).json({ message: `Team with id: ${safe.data.id} deleted successfully` });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: `Team with id: ${safe.data.id} was not able to be processed`,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("deleteOnly", "addRequestId")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
deleteTeam
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_DELETE", "addRequestId")(withValidQueryIdTransformParseInt(deleteTeam));
|
||||
@@ -1,36 +1,41 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaTeam, withValidTeam } from "@lib/validations/team";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { schemaTeam, withValidTeam } from "@lib/validations/team";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Team;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
error?: object;
|
||||
};
|
||||
|
||||
export async function editTeam(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, body, method } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaTeam.safeParse(body);
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
const safeBody = await schemaTeam.safeParse(req.body);
|
||||
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.team.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 })
|
||||
}
|
||||
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
|
||||
const data = await prisma.team.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
|
||||
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("patchOnly","addRequestId")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
withValidTeam(
|
||||
editTeam)
|
||||
)
|
||||
);
|
||||
export default withMiddleware(
|
||||
"HTTP_PATCH",
|
||||
"addRequestId"
|
||||
)(withValidQueryIdTransformParseInt(withValidTeam(editTeam)));
|
||||
@@ -1,30 +1,33 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Team;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
error?: object;
|
||||
};
|
||||
|
||||
export async function teamById(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const data = await prisma.team.findUnique({ where: { id: safe.data.id } });
|
||||
if (!safe.success) throw new Error("Invalid request query");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: "Team was not found" });
|
||||
}
|
||||
const data = await prisma.team.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "Team was not found",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
teamById
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(teamById));
|
||||
@@ -1,19 +1,26 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Team[];
|
||||
error?: unknown;
|
||||
message?: string;
|
||||
error?: object;
|
||||
};
|
||||
|
||||
async function allTeams(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const data = await prisma.team.findMany();
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(400).json({ error: "No data found" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "No Teams were found",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(allTeams);
|
||||
export default withMiddleware("HTTP_GET")(allTeams);
|
||||
+15
-12
@@ -2,10 +2,10 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaTeam, withValidTeam } from "@lib/validations/team";
|
||||
|
||||
|
||||
type ResponseData = {
|
||||
data?: Team;
|
||||
error?: object;
|
||||
@@ -13,16 +13,19 @@ type ResponseData = {
|
||||
|
||||
async function createTeam(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = schemaTeam.safeParse(req.body);
|
||||
if (safe.success) {
|
||||
const data = await prisma.team
|
||||
.create({ data: safe.data })
|
||||
if (data) res.status(201).json({ data })
|
||||
else (error: unknown) => res.status(400).json({ error: { message: "Could not create team type", error: error } });
|
||||
}
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
const data = await prisma.team.create({ data: safe.data });
|
||||
|
||||
if (data) res.status(201).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
error: {
|
||||
message: "Could not create new team",
|
||||
error,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("addRequestId","postOnly")(
|
||||
withValidTeam(
|
||||
createTeam
|
||||
)
|
||||
);
|
||||
export default withMiddleware("addRequestId", "HTTP_POST")(withValidTeam(createTeam));
|
||||
@@ -1,29 +1,27 @@
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import type { BaseResponse } from "@lib/types";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
};
|
||||
|
||||
export async function deleteUser(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
export async function deleteUser(req: NextApiRequest, res: NextApiResponse<BaseResponse>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const data = await prisma.user
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
// We only remove the user type from the database if there's an existing resource.
|
||||
if (data) res.status(200).json({ message: `User with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.user.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `User with id: ${safe.data.id} was not able to be processed` });
|
||||
}
|
||||
if (!safe.success) throw new Error("Invalid request query", safe.error);
|
||||
|
||||
const data = await prisma.user.delete({ where: { id: safe.data.id } });
|
||||
|
||||
if (data) res.status(200).json({ message: `User with id: ${safe.data.id} deleted successfully` });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: `User with id: ${safe.data.id} was not able to be processed`,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("deleteOnly", "addRequestId")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
deleteUser
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteUser));
|
||||
@@ -1,36 +1,33 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { User } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaUser, withValidUser } from "@lib/validations/user";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import type { UserResponse } from "@lib/types";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { schemaUserBodyParams, schemaUserPublic, withValidUser } from "@lib/validations/user";
|
||||
|
||||
type ResponseData = {
|
||||
data?: User;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
};
|
||||
export async function editUser(req: NextApiRequest, res: NextApiResponse<UserResponse>) {
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
const safeBody = await schemaUserBodyParams.safeParse(req.body);
|
||||
|
||||
export async function editUser(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, body, method } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaUser.safeParse(body);
|
||||
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
|
||||
const user = await prisma.user.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
const data = schemaUserPublic.parse(user);
|
||||
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.user.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 })
|
||||
}
|
||||
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("patchOnly","addRequestId")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
withValidUser(
|
||||
editUser)
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_PATCH")(withValidQueryIdTransformParseInt(withValidUser(editUser)));
|
||||
@@ -1,30 +1,29 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { User } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { UserResponse } from "@lib/types";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { schemaUserPublic } from "@lib/validations/user";
|
||||
|
||||
type ResponseData = {
|
||||
data?: User;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
};
|
||||
|
||||
export async function userById(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
export async function userById(req: NextApiRequest, res: NextApiResponse<UserResponse>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const data = await prisma.user.findUnique({ where: { id: safe.data.id } });
|
||||
if (!safe.success) throw new Error("Invalid request query");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: "User was not found" });
|
||||
}
|
||||
const user = await prisma.user.findUnique({ where: { id: safe.data.id } });
|
||||
const data = schemaUserPublic.parse(user);
|
||||
|
||||
if (user) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "User was not found",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
userById
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(userById));
|
||||
+15
-12
@@ -1,19 +1,22 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { User } from "@calcom/prisma/client";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
type ResponseData = {
|
||||
data?: User[];
|
||||
error?: unknown;
|
||||
};
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
async function allUsers(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const data = await prisma.user.findMany();
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { UsersResponse } from "@lib/types";
|
||||
import { schemaUserPublic } from "@lib/validations/user";
|
||||
|
||||
async function allUsers(_: NextApiRequest, res: NextApiResponse<UsersResponse>) {
|
||||
const users = await prisma.user.findMany();
|
||||
const data = users.map((user) => schemaUserPublic.parse(user));
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(400).json({ error: "No data found" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "No Users were found",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(allUsers);
|
||||
export default withMiddleware("HTTP_GET")(allUsers);
|
||||
+16
-19
@@ -1,28 +1,25 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { User } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaUser, withValidUser } from "@lib/validations/user";
|
||||
import type { UserResponse } from "@lib/types";
|
||||
import { schemaUserBodyParams, schemaUserPublic, withValidUser } from "@lib/validations/user";
|
||||
|
||||
async function createUser(req: NextApiRequest, res: NextApiResponse<UserResponse>) {
|
||||
const safe = schemaUserBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
type ResponseData = {
|
||||
data?: User;
|
||||
error?: object;
|
||||
};
|
||||
const user = await prisma.user.create({ data: safe.data });
|
||||
const data = schemaUserPublic.parse(user);
|
||||
|
||||
async function createUser(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = schemaUser.safeParse(req.body);
|
||||
if (safe.success) {
|
||||
const data = await prisma.user
|
||||
.create({ data: safe.data })
|
||||
if (data) res.status(201).json({ data })
|
||||
else (error: unknown) => res.status(400).json({ error: { message: "Could not create user type", error: error } });
|
||||
}
|
||||
if (data) res.status(201).json({ data, message: "User created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new user",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("addRequestId","postOnly")(
|
||||
withValidUser(
|
||||
createUser
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_POST")(withValidUser(createUser));
|
||||
Reference in new issue
Block a user