|
| 1 | +// Seed script for FlowOps - Run with: node seed-data.js |
| 2 | + |
| 3 | +const API_URL = 'https://flowops-backend.azurewebsites.net/api'; |
| 4 | + |
| 5 | +async function seedData() { |
| 6 | + console.log('🌱 Seeding FlowOps database...\n'); |
| 7 | + |
| 8 | + // 1. Register test user |
| 9 | + console.log('1. Creating test user...'); |
| 10 | + try { |
| 11 | + const registerRes = await fetch(`${API_URL}/auth/register`, { |
| 12 | + method: 'POST', |
| 13 | + headers: { 'Content-Type': 'application/json' }, |
| 14 | + body: JSON.stringify({ |
| 15 | + name: 'Demo User', |
| 16 | + |
| 17 | + password: 'Demo123!@#' |
| 18 | + }) |
| 19 | + }); |
| 20 | + const registerData = await registerRes.json(); |
| 21 | + console.log(' User created:', registerData.success ? '✅' : registerData.message || '❌'); |
| 22 | + } catch (e) { |
| 23 | + console.log(' User might already exist'); |
| 24 | + } |
| 25 | + |
| 26 | + // 2. Login to get token |
| 27 | + console.log('2. Logging in...'); |
| 28 | + const loginRes = await fetch(`${API_URL}/auth/login`, { |
| 29 | + method: 'POST', |
| 30 | + headers: { 'Content-Type': 'application/json' }, |
| 31 | + body: JSON.stringify({ |
| 32 | + |
| 33 | + password: 'Demo123!@#' |
| 34 | + }) |
| 35 | + }); |
| 36 | + const loginData = await loginRes.json(); |
| 37 | + |
| 38 | + if (!loginData.token) { |
| 39 | + console.log('❌ Login failed:', loginData); |
| 40 | + return; |
| 41 | + } |
| 42 | + console.log(' Token received: ✅\n'); |
| 43 | + |
| 44 | + const token = loginData.token; |
| 45 | + const headers = { |
| 46 | + 'Content-Type': 'application/json', |
| 47 | + 'Authorization': `Bearer ${token}` |
| 48 | + }; |
| 49 | + |
| 50 | + // 3. Create sample projects |
| 51 | + console.log('3. Creating sample projects...'); |
| 52 | + |
| 53 | + const projects = [ |
| 54 | + { |
| 55 | + name: 'E-Commerce Platform', |
| 56 | + description: 'Développement d\'une plateforme e-commerce complète avec panier, paiement et gestion des commandes.', |
| 57 | + status: 'in_progress' |
| 58 | + }, |
| 59 | + { |
| 60 | + name: 'Mobile Banking App', |
| 61 | + description: 'Application mobile de banking avec authentification biométrique et transferts en temps réel.', |
| 62 | + status: 'planned' |
| 63 | + }, |
| 64 | + { |
| 65 | + name: 'CRM Dashboard', |
| 66 | + description: 'Tableau de bord CRM pour la gestion des clients, leads et opportunités commerciales.', |
| 67 | + status: 'in_progress' |
| 68 | + } |
| 69 | + ]; |
| 70 | + |
| 71 | + const createdProjects = []; |
| 72 | + for (const project of projects) { |
| 73 | + const res = await fetch(`${API_URL}/projects`, { |
| 74 | + method: 'POST', |
| 75 | + headers, |
| 76 | + body: JSON.stringify(project) |
| 77 | + }); |
| 78 | + const data = await res.json(); |
| 79 | + if (data.data || data._id) { |
| 80 | + createdProjects.push(data.data || data); |
| 81 | + console.log(` ✅ Created: ${project.name}`); |
| 82 | + } else { |
| 83 | + console.log(` ⚠️ ${project.name}:`, data.message || 'already exists'); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + if (createdProjects.length === 0) { |
| 88 | + console.log('\n No new projects created. Fetching existing...'); |
| 89 | + const existingRes = await fetch(`${API_URL}/projects`, { headers }); |
| 90 | + const existingData = await existingRes.json(); |
| 91 | + if (existingData.data) { |
| 92 | + createdProjects.push(...existingData.data.slice(0, 3)); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + // 4. Create sample tasks for each project |
| 97 | + console.log('\n4. Creating sample tasks...'); |
| 98 | + |
| 99 | + const taskTemplates = [ |
| 100 | + // To Do |
| 101 | + { title: 'Setup project structure', status: 'todo', priority: 'high', type: 'task', storyPoints: 5 }, |
| 102 | + { title: 'Design database schema', status: 'todo', priority: 'highest', type: 'story', storyPoints: 8 }, |
| 103 | + { title: 'Create wireframes', status: 'todo', priority: 'medium', type: 'task', storyPoints: 3 }, |
| 104 | + { title: 'Write API documentation', status: 'todo', priority: 'low', type: 'task', storyPoints: 2 }, |
| 105 | + |
| 106 | + // Doing (In Progress) |
| 107 | + { title: 'Implement user authentication', status: 'doing', priority: 'highest', type: 'story', storyPoints: 8 }, |
| 108 | + { title: 'Build REST API endpoints', status: 'doing', priority: 'high', type: 'task', storyPoints: 5 }, |
| 109 | + { title: 'Create React components', status: 'doing', priority: 'medium', type: 'task', storyPoints: 5 }, |
| 110 | + |
| 111 | + // Review |
| 112 | + { title: 'Code review for login feature', status: 'review', priority: 'high', type: 'task', storyPoints: 2 }, |
| 113 | + { title: 'Security audit implementation', status: 'review', priority: 'highest', type: 'bug', storyPoints: 3 }, |
| 114 | + |
| 115 | + // Done |
| 116 | + { title: 'Initial project setup', status: 'done', priority: 'high', type: 'task', storyPoints: 3 }, |
| 117 | + { title: 'Configure CI/CD pipeline', status: 'done', priority: 'medium', type: 'story', storyPoints: 5 }, |
| 118 | + { title: 'Setup Docker containers', status: 'done', priority: 'medium', type: 'task', storyPoints: 3 } |
| 119 | + ]; |
| 120 | + |
| 121 | + for (const project of createdProjects) { |
| 122 | + const projectId = project._id || project.id; |
| 123 | + if (!projectId) continue; |
| 124 | + |
| 125 | + console.log(` 📁 Adding tasks to: ${project.name} (ID: ${projectId})`); |
| 126 | + |
| 127 | + for (const task of taskTemplates) { |
| 128 | + try { |
| 129 | + const res = await fetch(`${API_URL}/projects/${projectId}/tasks`, { |
| 130 | + method: 'POST', |
| 131 | + headers, |
| 132 | + body: JSON.stringify({ |
| 133 | + ...task, |
| 134 | + description: `Task: ${task.title} for project ${project.name}` |
| 135 | + }) |
| 136 | + }); |
| 137 | + const data = await res.json(); |
| 138 | + if (data.success && data.data) { |
| 139 | + console.log(` ✅ ${task.title} (${data.data.taskKey})`); |
| 140 | + } else { |
| 141 | + console.log(` ❌ ${task.title}: ${data.message || JSON.stringify(data)}`); |
| 142 | + } |
| 143 | + } catch (e) { |
| 144 | + console.log(` ❌ Failed: ${task.title} - ${e.message}`); |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + console.log('\n✅ Seeding complete!'); |
| 150 | + console.log('\n📋 Login credentials:'); |
| 151 | + console.log(' Email: [email protected]'); |
| 152 | + console.log(' Password: Demo123!@#'); |
| 153 | + console.log('\n🌐 URL: https://flowops-frontend.azurewebsites.net'); |
| 154 | +} |
| 155 | + |
| 156 | +seedData().catch(console.error); |
0 commit comments