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
|
|
|
|
2022-03-31 20:14:37 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
|
|
|
import { MembershipsResponse } from "@lib/types";
|
|
|
|
import { schemaMembershipPublic } from "@lib/validations/membership";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /api/memberships:
|
|
|
|
* get:
|
|
|
|
* summary: Returns all memberships
|
|
|
|
* tags:
|
|
|
|
* - memberships
|
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
* 404:
|
|
|
|
* description: No memberships were found
|
|
|
|
*/
|
|
|
|
async function allMemberships(_: NextApiRequest, res: NextApiResponse<MembershipsResponse>) {
|
|
|
|
const memberships = await prisma.membership.findMany();
|
|
|
|
const data = memberships.map((membership) => schemaMembershipPublic.parse(membership));
|
2022-03-28 22:27:14 +00:00
|
|
|
|
|
|
|
if (data) res.status(200).json({ data });
|
2022-03-31 20:14:37 +00:00
|
|
|
else
|
|
|
|
(error: Error) =>
|
|
|
|
res.status(404).json({
|
|
|
|
message: "No Memberships were found",
|
|
|
|
error,
|
|
|
|
});
|
2022-03-28 22:27:14 +00:00
|
|
|
}
|
2022-03-31 20:14:37 +00:00
|
|
|
|
|
|
|
export default withMiddleware("HTTP_GET")(allMemberships);
|