2022-03-30 12:17:55 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-03-28 22:27:14 +00:00
|
|
|
import { DestinationCalendar } from "@calcom/prisma/client";
|
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
import {
|
|
|
|
schemaDestinationCalendar,
|
|
|
|
withValidDestinationCalendar,
|
|
|
|
} from "@lib/validations/destination-calendar";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
|
|
|
type ResponseData = {
|
|
|
|
data?: DestinationCalendar;
|
|
|
|
message?: string;
|
|
|
|
error?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
async function createDestinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
|
|
|
const { body, method } = req;
|
|
|
|
const safe = schemaDestinationCalendar.safeParse(body);
|
|
|
|
if (method === "POST" && safe.success) {
|
2022-03-30 12:17:55 +00:00
|
|
|
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
|
2022-03-28 22:27:14 +00:00
|
|
|
} else res.status(405).json({ error: "Only POST Method allowed" });
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withValidDestinationCalendar(createDestinationCalendar);
|