2022-09-05 19:31:12 +00:00
|
|
|
import type { NextApiRequest } from "next";
|
|
|
|
|
2022-09-06 17:20:04 +00:00
|
|
|
import { defaultResponder } from "@calcom/lib/server";
|
2022-09-05 19:31:12 +00:00
|
|
|
|
|
|
|
import { schemaUserReadPublic } from "@lib/validations/user";
|
|
|
|
|
|
|
|
import { User } from ".prisma/client";
|
|
|
|
|
|
|
|
async function handler(req: NextApiRequest): Promise<{ error?: string; user?: Partial<User> }> {
|
|
|
|
if (!prisma) return { error: "Cant connect to database" };
|
|
|
|
console.log(req);
|
|
|
|
if (!req.userId) return { error: "No user id found" };
|
|
|
|
const data = await prisma.user.findUniqueOrThrow({ where: { id: req.userId } });
|
|
|
|
if (!data) return { error: "You need to pass apiKey" };
|
|
|
|
const user = schemaUserReadPublic.parse(data);
|
|
|
|
return { user };
|
|
|
|
}
|
|
|
|
|
2022-09-06 17:20:04 +00:00
|
|
|
export default defaultResponder(handler);
|