diff --git a/pages/api/collections/[identifier]/cards.js b/pages/api/collections/[identifier]/cards.js index 583d161..c1c460a 100644 --- a/pages/api/collections/[identifier]/cards.js +++ b/pages/api/collections/[identifier]/cards.js @@ -59,11 +59,11 @@ export default async function handler(req, res) { `; } - if (collectionResult.length === 0) { + if (collectionResult.rows.length === 0) { return res.status(404).json({ error: 'Collection not found or access denied' }); } - const collection = collectionResult[0]; + const collection = collectionResult.rows[0]; if (req.method === 'GET') { // Get all cards in the collection @@ -78,7 +78,7 @@ export default async function handler(req, res) { ORDER BY cc.created_at DESC `; - const cards = cardsResult.map(card => ({ + const cards = cardsResult.rows.map(card => ({ id: card.id, name: card.name, set_name: card.set_name, @@ -196,13 +196,13 @@ export default async function handler(req, res) { RETURNING * `; - if (result.length === 0) { + if (result.rows.length === 0) { return res.status(404).json({ error: 'Card not found in collection' }); } res.status(200).json({ message: 'Card quantity updated', - card: result[0] + card: result.rows[0] }); } @@ -234,7 +234,7 @@ export default async function handler(req, res) { RETURNING * `; - if (result.length === 0) { + if (result.rows.length === 0) { return res.status(404).json({ error: 'Card not found in collection' }); } @@ -255,4 +255,4 @@ export default async function handler(req, res) { console.error('Collection cards API error:', error); res.status(500).json({ error: 'Internal server error' }); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/pages/api/collections/[identifier]/permissions.js b/pages/api/collections/[identifier]/permissions.js index 5bfc233..fbb355d 100644 --- a/pages/api/collections/[identifier]/permissions.js +++ b/pages/api/collections/[identifier]/permissions.js @@ -45,11 +45,11 @@ export default async function handler(req, res) { `; } - if (collectionResult.length === 0) { + if (collectionResult.rows.length === 0) { return res.status(404).json({ error: 'Collection not found or you do not have permission to manage permissions' }); } - const collection = collectionResult[0]; + const collection = collectionResult.rows[0]; if (req.method === 'GET') { // Get all permissions for this collection @@ -65,7 +65,7 @@ export default async function handler(req, res) { ORDER BY cp.created_at DESC `; - const permissions = permissionsResult.map(perm => ({ + const permissions = permissionsResult.rows.map(perm => ({ id: perm.id, userId: perm.user_id, email: perm.email, diff --git a/pages/api/collections/[identifier]/thumbnails.js b/pages/api/collections/[identifier]/thumbnails.js index 612d244..a86c730 100644 --- a/pages/api/collections/[identifier]/thumbnails.js +++ b/pages/api/collections/[identifier]/thumbnails.js @@ -83,7 +83,7 @@ export default async function handler(req, res) { // Get the top 5 rarest cards from the collection const thumbnailsResult = await sql` - SELECT DISTINCT + SELECT cards.id, cards.name, cards.rarity,