cal.pub0.org/pages/api/availability/week.ts

32 lines
744 B
TypeScript
Raw Normal View History

2021-07-07 10:43:13 +00:00
import type { NextApiRequest, NextApiResponse } from "next";
import { getSession } from "@lib/auth";
2021-07-07 10:43:13 +00:00
import prisma from "../../../lib/prisma";
2021-06-14 18:53:20 +00:00
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
2021-07-07 10:43:13 +00:00
const session = await getSession({ req: req });
2021-06-14 18:53:20 +00:00
if (!session) {
2021-07-07 10:43:13 +00:00
res.status(401).json({ message: "Not authenticated" });
2021-06-14 18:53:20 +00:00
return;
}
if (req.method == "PATCH") {
const startMins = req.body.start;
const endMins = req.body.end;
2021-07-07 10:43:13 +00:00
await prisma.schedule.update({
2021-06-14 18:53:20 +00:00
where: {
id: session.user.id,
},
data: {
startTime: startMins,
2021-07-07 10:43:13 +00:00
endTime: endMins,
2021-06-14 18:53:20 +00:00
},
});
2021-07-07 10:43:13 +00:00
res.status(200).json({ message: "Start and end times updated successfully" });
2021-06-14 18:53:20 +00:00
}
2021-07-07 10:43:13 +00:00
}