cal.pub0.org/pages/api/daily-event-references/index.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-30 12:17:55 +00:00
import type { NextApiRequest, NextApiResponse } from "next";
2022-03-30 12:17:55 +00:00
import prisma from "@calcom/prisma";
2022-04-01 23:55:41 +00:00
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DailyEventReferencesResponse } from "@lib/types";
import { schemaDailyEventReferencePublic } from "@lib/validations/daily-event-reference";
/**
* @swagger
* /api/daily-event-references:
* get:
* summary: Get all dailyEventReferences
* tags:
* - daily-event-references
2022-04-01 23:55:41 +00:00
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No dailyEventReferences were found
*/
async function allDailyEventReferences(
_: NextApiRequest,
res: NextApiResponse<DailyEventReferencesResponse>
) {
const dailyEventReferences = await prisma.dailyEventReference.findMany();
const data = dailyEventReferences.map((dailyEventReference) =>
schemaDailyEventReferencePublic.parse(dailyEventReference)
);
if (data) res.status(200).json({ data });
2022-04-01 23:55:41 +00:00
else
(error: Error) =>
res.status(404).json({
message: "No DailyEventReferences were found",
error,
});
}
2022-04-01 23:55:41 +00:00
export default withMiddleware("HTTP_GET")(allDailyEventReferences);