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 { favorited } = req.body; try { // Update the card's favorite status const result = await sql` UPDATE cards SET favorited = ${favorited} WHERE id = ${id} RETURNING id, name, favorited `; 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 favorite status:', error); res.status(500).json({ error: 'Failed to update favorite status' }); } }