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

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  try {
    if (req.method === "GET") {
      const db = postgresConnection;

      const result = await db.query("select * from get_game_config()");
      if (result.rowCount > 0) {
        return res.status(200).json(result.rows[0]);
      } else {
        return res.status(404).json({ message: "Something went wrong" });
      }
    }
  } catch (error) {
    res.status(500).json(error);
  }
}
