diff --git a/pages/api/cards/search.js b/pages/api/cards/search.js index 3463a74..3cddbd1 100644 --- a/pages/api/cards/search.js +++ b/pages/api/cards/search.js @@ -32,6 +32,9 @@ export default async function handler(req, res) { const limitNum = parseInt(limit) || 50; const offset = (pageNum - 1) * limitNum; + // Define the columns we want to select (only existing columns) + // Note: removed flavor_text, hp, type, form, weakness, retreat_cost as they don't exist in the current schema + // Normalize filters const filters = { hasQuery: query.trim() !== '', @@ -49,10 +52,10 @@ export default async function handler(req, res) { // No filters - get all cards result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, - mana_cost, cmc, card_type, colors, oracle_text, flavor_text, + mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, - quantity, hp, type, form, weakness, retreat_cost + quantity FROM cards ORDER BY name ASC LIMIT ${limitNum} OFFSET ${offset} @@ -63,10 +66,10 @@ export default async function handler(req, res) { // Search by name only result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, - mana_cost, cmc, card_type, colors, oracle_text, flavor_text, + mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, - quantity, hp, type, form, weakness, retreat_cost + quantity FROM cards WHERE name ILIKE ${`%${query.trim()}%`} ORDER BY name ASC @@ -78,10 +81,10 @@ export default async function handler(req, res) { // Filter by game only result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, - mana_cost, cmc, card_type, colors, oracle_text, flavor_text, + mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, - quantity, hp, type, form, weakness, retreat_cost + quantity FROM cards WHERE game = ${game} ORDER BY name ASC @@ -93,10 +96,10 @@ export default async function handler(req, res) { // Filter by rarity only result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, - mana_cost, cmc, card_type, colors, oracle_text, flavor_text, + mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, - quantity, hp, type, form, weakness, retreat_cost + quantity FROM cards WHERE rarity = ${rarity} ORDER BY name ASC @@ -108,10 +111,10 @@ export default async function handler(req, res) { // Filter by game and rarity result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, - mana_cost, cmc, card_type, colors, oracle_text, flavor_text, + mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, - quantity, hp, type, form, weakness, retreat_cost + quantity FROM cards WHERE game = ${game} AND rarity = ${rarity} ORDER BY name ASC @@ -123,10 +126,10 @@ export default async function handler(req, res) { // Search with game filter result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, - mana_cost, cmc, card_type, colors, oracle_text, flavor_text, + mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, - quantity, hp, type, form, weakness, retreat_cost + quantity FROM cards WHERE name ILIKE ${`%${query.trim()}%`} AND game = ${game} ORDER BY name ASC @@ -150,10 +153,10 @@ export default async function handler(req, res) { // For complex queries, use a fallback approach result = await sql` SELECT id, name, set_name, set_code, card_number, rarity, game, - mana_cost, cmc, card_type, colors, oracle_text, flavor_text, + mana_cost, cmc, card_type, colors, oracle_text, power, toughness, image_url, stock_image_url, current_price, market_price, scryfall_id, verified, - quantity, hp, type, form, weakness, retreat_cost + quantity FROM cards ORDER BY name ASC LIMIT ${limitNum} OFFSET ${offset}