2022-06-14 20:08:58 +00:00
|
|
|
import type { NextApiRequest } from "next";
|
|
|
|
|
2022-06-23 22:09:23 +00:00
|
|
|
import { HttpError } from "@calcom/lib/http-error";
|
2022-06-14 20:08:58 +00:00
|
|
|
import { defaultResponder } from "@calcom/lib/server";
|
|
|
|
|
|
|
|
import { schemaUserCreateBodyParams } from "@lib/validations/user";
|
|
|
|
|
|
|
|
async function postHandler(req: NextApiRequest) {
|
2022-06-23 22:53:15 +00:00
|
|
|
const { prisma, isAdmin } = req;
|
2022-06-14 20:08:58 +00:00
|
|
|
// If user is not ADMIN, return unauthorized.
|
|
|
|
if (!isAdmin) throw new HttpError({ statusCode: 401, message: "You are not authorized" });
|
|
|
|
const data = schemaUserCreateBodyParams.parse(req.body);
|
|
|
|
const user = await prisma.user.create({ data });
|
|
|
|
req.statusCode = 201;
|
|
|
|
return { user };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defaultResponder(postHandler);
|