11// Seed script for FlowOps - Run with: node seed-data.js
22
3- const API_URL = 'https://flowops-backend.azurewebsites.net/api' ;
3+ // Change to localhost for local testing, or use Azure backend for production
4+ const API_URL = process . env . API_URL || 'http://localhost:3001/api' ;
5+ // const API_URL = 'https://flowops-backend.azurewebsites.net/api';
46
57async function seedData ( ) {
68 console . log ( '🌱 Seeding FlowOps database...\n' ) ;
@@ -148,20 +150,27 @@ async function seedData() {
148150
149151 // 5. Create sample sprints for first project
150152 console . log ( '\n5. Creating sample sprints...' ) ;
151-
153+
152154 if ( createdProjects . length > 0 ) {
153155 const project = createdProjects [ 0 ] ;
154156 const projectId = project . _id || project . id ;
155-
156- // Get tasks for this project to add to sprints
157- const tasksRes = await fetch ( `${ API_URL } /projects/${ projectId } /tasks` , { headers } ) ;
158- const tasksData = await tasksRes . json ( ) ;
159- const projectTasks = tasksData . data || [ ] ;
160-
157+
158+ // Refresh tasks list for this project to ensure we have all tasks (newly created or existing)
159+ console . log ( ' 🔄 Fetching latest tasks for project...' ) ;
160+ let projectTasks = [ ] ;
161+ try {
162+ const tasksRes = await fetch ( `${ API_URL } /projects/${ projectId } /tasks` , { headers } ) ;
163+ const tasksData = await tasksRes . json ( ) ;
164+ projectTasks = tasksData . data || [ ] ;
165+ console . log ( ` ✅ Found ${ projectTasks . length } tasks available for sprints` ) ;
166+ } catch ( e ) {
167+ console . log ( ' ⚠️ Failed to fetch tasks:' , e . message ) ;
168+ }
169+
161170 const today = new Date ( ) ;
162171 const twoWeeksFromNow = new Date ( today . getTime ( ) + 14 * 24 * 60 * 60 * 1000 ) ;
163172 const fourWeeksFromNow = new Date ( today . getTime ( ) + 28 * 24 * 60 * 60 * 1000 ) ;
164-
173+
165174 const sprints = [
166175 {
167176 name : 'Sprint 1 - Foundation' ,
@@ -176,7 +185,7 @@ async function seedData() {
176185 endDate : fourWeeksFromNow . toISOString ( )
177186 }
178187 ] ;
179-
188+
180189 const createdSprints = [ ] ;
181190 for ( const sprint of sprints ) {
182191 try {
@@ -196,11 +205,11 @@ async function seedData() {
196205 console . log ( ` ❌ Failed: ${ sprint . name } - ${ e . message } ` ) ;
197206 }
198207 }
199-
208+
200209 // Start the first sprint and add tasks to it
201210 if ( createdSprints . length > 0 ) {
202211 const firstSprint = createdSprints [ 0 ] ;
203-
212+
204213 // Add some tasks to the sprint
205214 const taskIdsForSprint = projectTasks . slice ( 0 , 6 ) . map ( t => t . _id ) ;
206215 if ( taskIdsForSprint . length > 0 ) {
@@ -215,7 +224,7 @@ async function seedData() {
215224 console . log ( ` ❌ Failed to add tasks to sprint` ) ;
216225 }
217226 }
218-
227+
219228 // Start the sprint
220229 try {
221230 await fetch ( `${ API_URL } /sprints/${ firstSprint . _id } /start` , {
0 commit comments