calcom/pages/api/user/[id].ts
Femi Odugbesan 2d23a8b7db
Onboarding Flow (#503)
* wip

* wip

* db: schedule schema

* fix adding time goes into new day

fix adding new time not keeping updating ranges

fix updating ranges not maintaining changed values

* remove photo upload

* remove unused code

* remove more unused code

* undo time lib

* didnt actually change this

* dont show onboardi
ng flow for users created before sept 1 2021

* use more consistent max-widths

* align all inputs in scheduler component

* allow overriding of default styles

* match figma designs

implement goto previous step

* add more types, match figma

Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
2021-09-02 13:13:19 +01:00

48 lines
1.3 KiB
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@lib/prisma";
import { getSession } from "next-auth/client";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req: req });
if (!session) {
return res.status(401).json({ message: "Not authenticated" });
}
const userIdQuery = req.query?.id ?? null;
const userId = Array.isArray(userIdQuery) ? parseInt(userIdQuery.pop()) : parseInt(userIdQuery);
const authenticatedUser = await prisma.user.findFirst({
where: {
email: session.user.email,
},
select: {
id: true,
},
});
if (userId !== authenticatedUser.id) {
return res.status(401).json({ message: "Unauthorized" });
}
if (req.method === "GET") {
return res.status(405).json({ message: "Method Not Allowed" });
}
if (req.method === "DELETE") {
return res.status(405).json({ message: "Method Not Allowed" });
}
if (req.method === "PATCH") {
const data = req.body.data;
const updatedUser = await prisma.user.update({
where: {
id: authenticatedUser.id,
},
data: {
...data,
},
});
return res.status(200).json({ message: "User Updated", data: updatedUser });
}
}