2022-03-30 12:17:55 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
2022-03-25 22:26:22 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
|
2022-03-29 01:23:22 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
2022-03-30 12:17:55 +00:00
|
|
|
import { UsersResponse } from "@lib/types";
|
|
|
|
import { schemaUserPublic } from "@lib/validations/user";
|
2022-03-25 22:26:22 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
async function allUsers(_: NextApiRequest, res: NextApiResponse<UsersResponse>) {
|
|
|
|
const users = await prisma.user.findMany();
|
|
|
|
const data = users.map((user) => schemaUserPublic.parse(user));
|
2022-03-29 01:59:57 +00:00
|
|
|
|
2022-03-28 22:27:14 +00:00
|
|
|
if (data) res.status(200).json({ data });
|
2022-03-30 12:17:55 +00:00
|
|
|
else
|
|
|
|
(error: Error) =>
|
|
|
|
res.status(400).json({
|
|
|
|
message: "No Users were found",
|
|
|
|
error,
|
|
|
|
});
|
2022-03-25 22:26:22 +00:00
|
|
|
}
|
2022-03-29 01:23:22 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
export default withMiddleware("HTTP_GET")(allUsers);
|