import { postgresConnection } from "db"; import type { NextApiRequest, NextApiResponse } from "next"; import { calculateRemainingTime, } from "../../../../../utils/helpers"; import { gameConfig } from "@/utils/gameLogic"; export default async function handler( req: NextApiRequest, res: NextApiResponse ) { try { if (req.method === "POST") { const { userId } = req.query; const { inventoryItemId, wellId } = req.body; const db = postgresConnection; try { const result = await db.query("SELECT * FROM stake($1, $2, $3) AS stake", [ userId, wellId, inventoryItemId]); return res.status(200).json({stakingEventId: result.rows[0].stake}); // if (invItem.stakeId != undefined) { // const timeRemaining = calculateRemainingTime(invItem.stakeTime, invItem.duration_in_mins); // if (timeRemaining > 0) { // return res.status(400).json({error: `Item is still in use ${timeRemaining}`}); // } // } // const boost = invItem.tier > 0 ? item.upgrades[invItem.tier - 1].claimBoost : 0; // const totalClaim = item.claimAmount + boost; // await db.run(`INSERT INTO staking_event(user_id, well_id, inventory_item_id, duration_in_mins, stake_amount) // VALUES (?,?,?,?,?)`, // [userId, well.id, invItem.id, item.completionTimeInMins, totalClaim]); } catch (error) { return res.status(400).json({ error: error.message}); } } } catch (error) { if (error instanceof Error){ res.status(500).json(error.message); } else { res.status(500).json({ error: "Unknown Error"}); } } }