import { postgresConnection } from "db";
import type { NextApiRequest, NextApiResponse } from "next";

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  try {
    if (req.method === "POST") {
      let { userId } = req.query;

      const db = postgresConnection;

      const result = await db.query("select clear_user_data($1)", [userId]);
      console.log(result);
      if (result.rowCount > 0) {
        return res.status(200).json({message: "Success!"});
      } else {
        return res.status(404).json({ message: "User not found" });
      }
    }
  } catch (error) {
    res.status(500).json(error.message);
  }
}
