* Migrate legacy api endpoints to tRPC II (#3865) * fix: delete api route /api/availability/day * fix: delete api route /api/availability/eventtype (#3573) * fix: delete api route /api/event-type (#3573) * migrate /api/book/confirm to viewer.bookings.confirm * Merge branch 'main' into pr/3865 Co-authored-by: hussamkhatib <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: zomars <[email protected]> * Import fixes * Import fixes Co-authored-by: mohammed hussam <[email protected]> Co-authored-by: hussamkhatib <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
10 files changed
+391
-821
No files matched your search
@@ -1,33 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { getSession } from "@lib/auth";
|
||||
|
||||
import prisma from "../../../lib/prisma";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({ req: req });
|
||||
|
||||
if (!session) {
|
||||
res.status(401).json({ message: "Not authenticated" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method == "PATCH") {
|
||||
const startMins = req.body.start;
|
||||
const endMins = req.body.end;
|
||||
const bufferMins = req.body.buffer;
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: session.user.id,
|
||||
},
|
||||
data: {
|
||||
startTime: startMins,
|
||||
endTime: endMins,
|
||||
bufferTime: bufferMins,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(200).json({ message: "Start and end times updated successfully" });
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { createContext } from "@calcom/trpc/server/createContext";
|
||||
import { viewerRouter } from "@calcom/trpc/server/routers/viewer";
|
||||
|
||||
import { getSession } from "@lib/auth";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({ req });
|
||||
/** So we can reuse tRCP queries */
|
||||
const trpcCtx = await createContext({ req, res });
|
||||
|
||||
if (!session?.user?.id) {
|
||||
res.status(401).json({ message: "Not authenticated" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "POST") {
|
||||
const eventType = await viewerRouter.createCaller(trpcCtx).mutation("eventTypes.create", req.body);
|
||||
res.status(201).json({ eventType });
|
||||
}
|
||||
|
||||
if (req.method === "PATCH") {
|
||||
const eventType = await viewerRouter.createCaller(trpcCtx).mutation("eventTypes.update", req.body);
|
||||
res.status(201).json({ eventType });
|
||||
}
|
||||
|
||||
if (req.method === "DELETE") {
|
||||
await viewerRouter.createCaller(trpcCtx).mutation("eventTypes.delete", { id: req.body.id });
|
||||
res.status(200).json({ id: req.body.id, message: "Event Type deleted" });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user