import { postgresConnection } from "db";
import type { NextApiRequest, NextApiResponse } from "next";
import { IInventoryItem } from "typings";
import { updateAllToCamelCase } from "@/utils/helpers";

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

      const result = await db.query("SELECT * FROM get_all_stakes($1)", [userId]);

      return res.status(200).json({stakes: result.rows});
    }
  } catch (error) {
    res.status(500).json(error.message);
  }
}
