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

34 lines
812 B
TypeScript
Raw Normal View History

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