cal.pub0.org/pages/api/api-keys/[id]/index.ts

25 lines
865 B
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";
import { ApiKey } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
2022-03-30 12:17:55 +00:00
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
type ResponseData = {
data?: ApiKey;
error?: unknown;
};
export async function apiKeyById(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const safe = await schemaQueryIdAsString.safeParse(req.query);
if (safe.success) {
const data = await prisma.apiKey.findUnique({ where: { id: safe.data.id } });
if (data) res.status(200).json({ data });
2022-03-30 12:17:55 +00:00
else res.status(404).json({ error: { message: "ApiKey was not found" } });
}
}
2022-03-30 12:17:55 +00:00
export default withMiddleware("addRequestId", "HTTP_GET")(withValidQueryIdString(apiKeyById));