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

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  try {
    console.log("Loading config...")
    if (req.method === "POST") {
      const db = postgresConnection;
      const result = await db.query("select import_config();");
      console.log(result)
      if (result.rowCount > 0) {
        return res.status(200).json({ userId: result.rows[0].id});
      } else {
        return res.status(404).json({ message: "User not found" });
      }
    }
  } catch (error) {
    res.status(500).json(error);
  }
}
