deckhearth/scripts/add-favorites-system.js

45 lines
1.7 KiB
JavaScript
Raw Normal View History

🚀 Implemented Complete Collection Functionality Built out all requested features from top to bottom: ✅ Upload Modal for Hero Images: - Created UploadImageModal component with drag-and-drop - Support for both URL input and file upload - Live preview and validation - Integrated into collection detail page ✅ Smart TCG Tags: - Dynamic tags showing only games with cards - Properly positioned under description - Clean blue rounded styling ✅ Combined Share & Invite Modal: - Unified ShareModal replacing separate buttons - Public access toggle with community visibility - Email/member search functionality - Default viewer role for invitations - Social sharing (Twitter, Facebook, Reddit, Discord) - User search API endpoint (/api/users/search) ✅ Comprehensive Favorites System: - Database schema for cards, collections, and decks - API endpoint (/api/favorites) for CRUD operations - Real-time favorite status checking - Working toggle functionality in UI - Migration script for database setup ✅ CSV Download Functionality: - Complete card metadata export - Proper CSV formatting with escaping - All card fields included (name, set, rarity, etc.) - Automatic filename generation - Client-side download implementation 🎯 UI/UX Improvements: - Removed duplicate buttons and switches - Clean action bar with proper hierarchy - Working modals with proper state management - Error handling and loading states 🛠️ Technical Features: - JWT authentication for all endpoints - Proper database relationships and indexes - CORS headers and error handling - Optimized queries and performance All todos completed! Ready for full collection management! 🎮✨
2025-07-25 23:28:52 -04:00
#!/usr/bin/env node
import { config } from 'dotenv';
import { sql } from '@vercel/postgres';
config({ path: '.env.local' });
async function addFavoritesSystem() {
try {
console.log('⭐ Adding favorites system to database...');
// Create user_favorites table for all types of favorites
await sql`
CREATE TABLE IF NOT EXISTS user_favorites (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
item_type VARCHAR(50) NOT NULL, -- 'card', 'collection', 'deck'
item_id INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(user_id, item_type, item_id)
)
`;
console.log('✅ Created user_favorites table');
// Create indexes for performance
await sql`
CREATE INDEX IF NOT EXISTS idx_user_favorites_user_id ON user_favorites(user_id);
CREATE INDEX IF NOT EXISTS idx_user_favorites_item_type ON user_favorites(item_type);
CREATE INDEX IF NOT EXISTS idx_user_favorites_item_id ON user_favorites(item_id);
CREATE INDEX IF NOT EXISTS idx_user_favorites_user_type ON user_favorites(user_id, item_type);
`;
console.log('⚡ Created indexes for user_favorites');
console.log('\n🎉 Favorites system added successfully!\n');
console.log('📋 New Features:');
console.log(' • Users can favorite cards, collections, and decks');
console.log(' • Unified favorites table with item_type and item_id');
console.log(' • Optimized with indexes for fast queries');
console.log(' • Unique constraint prevents duplicate favorites');
} catch (error) {
console.error('❌ Failed to add favorites system:', error);
process.exit(1);
}
}
addFavoritesSystem();