2021-08-18 11:52:25 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-08-18 11:52:25 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-08-18 11:52:25 +00:00
|
|
|
import prisma from "../../../lib/prisma";
|
2021-04-13 16:16:32 +00:00
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
2021-08-19 12:27:01 +00:00
|
|
|
const session = await getSession({ req: req });
|
2021-04-13 16:16:32 +00:00
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
if (!session) {
|
|
|
|
res.status(401).json({ message: "Not authenticated" });
|
|
|
|
return;
|
|
|
|
}
|
2021-04-13 16:16:32 +00:00
|
|
|
|
2021-08-19 12:27:01 +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
|
|
|
|
2021-08-19 12:27:01 +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
|
|
|
|
2021-08-19 12:27:01 +00:00
|
|
|
res.status(200).json({ message: "Start and end times updated successfully" });
|
|
|
|
}
|
2021-06-15 16:19:00 +00:00
|
|
|
}
|