text: import { getSession } from "next-auth/react";
  import prisma from "lib/prisma";
  
  export default async function handler(req, res) {
      const session = await getSession({ req });
  
      const { id } = req.query;
      const { email } = session.user;
      const entry = await prisma.guestbook.findUnique({
          where: {
              id: id,
          },
      });
  
      if (req.method === "GET") {
          return res.json({
              id: entry.id.toString(),
              body: entry.body,
              created_by: entry.created_by,
              updated_at: entry.updated_at,
          });
      }
  
      if (!session || email !== entry.email) {
          return res.status(403).send("Unauthorized");
      }
  
      if (req.method === "DELETE") {
          await prisma.guestbook.delete({
              where: {
                  id: id,
              },
          });
  
          return res.status(204).end();
      }
  
      if (req.method === "PUT") {
          const body = (req.body.body || "").slice(0, 500);
  
          await prisma.guestbook.update({
              where: {
                  id: id,
              },
              data: {
                  body,
                  updated_at: new Date().toISOString(),
              },
          });
  
          return res.status(201).json({
              ...entry,
              body,
          });
      }
  
      return res.send("Method not allowed.");
  }
  