2022-05-06 17:21:30 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { JSONObject } from "superjson/dist/types";
|
|
|
|
|
2022-07-06 19:31:07 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
|
2022-05-06 17:21:30 +00:00
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
if (req.method === "GET" && req.session && req.session.user.id) {
|
|
|
|
const userId = req.session.user.id;
|
|
|
|
try {
|
2022-07-06 19:31:07 +00:00
|
|
|
const user = await prisma.user.findFirst({
|
2022-05-06 17:21:30 +00:00
|
|
|
select: {
|
|
|
|
metadata: true,
|
|
|
|
},
|
|
|
|
where: {
|
|
|
|
id: userId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (user && user.metadata && (user.metadata as JSONObject)?.vitalSettings) {
|
|
|
|
res.status(200).json((user.metadata as JSONObject).vitalSettings);
|
|
|
|
} else {
|
|
|
|
res.status(404);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
res.status(500);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.status(400);
|
|
|
|
}
|
|
|
|
res.end();
|
|
|
|
}
|