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 { Membership } from "@calcom/prisma/client";
|
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
import {
|
|
|
|
schemaQueryIdParseInt,
|
|
|
|
withValidQueryIdTransformParseInt,
|
|
|
|
} from "@lib/validations/shared/queryIdTransformParseInt";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
|
|
|
type ResponseData = {
|
|
|
|
data?: Membership;
|
|
|
|
message?: string;
|
|
|
|
error?: unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function membership(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
|
|
|
const { query, method } = req;
|
|
|
|
const safe = await schemaQueryIdParseInt.safeParse(query);
|
|
|
|
if (method === "GET" && safe.success) {
|
|
|
|
const data = await prisma.membership.findUnique({ where: { id: safe.data.id } });
|
|
|
|
|
|
|
|
if (data) res.status(200).json({ data });
|
2022-03-29 01:59:57 +00:00
|
|
|
else res.status(404).json({ message: "Event type not found" });
|
2022-03-28 22:27:14 +00:00
|
|
|
// Reject any other HTTP method than POST
|
|
|
|
} else res.status(405).json({ message: "Only GET Method allowed" });
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withValidQueryIdTransformParseInt(membership);
|