import { sql } from '@vercel/postgres'; export default async function handler(req, res) { if (req.method !== 'POST') { return res.status(405).json({ error: 'Method not allowed' }); } const { id } = req.query; const { quantity } = req.body; try { // Update the card's quantity const result = await sql` UPDATE cards SET quantity = ${quantity} WHERE id = ${id} RETURNING id, name, quantity `; if (result.rows.length === 0) { return res.status(404).json({ error: 'Card not found' }); } res.status(200).json({ success: true, card: result.rows[0] }); } catch (error) { console.error('Error updating ownership:', error); res.status(500).json({ error: 'Failed to update ownership' }); } }