-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed-data.js
More file actions
324 lines (284 loc) · 13.2 KB
/
Copy pathseed-data.js
File metadata and controls
324 lines (284 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// Seed script for FlowOps - Run with: node seed-data.js
// Use API_URL=http://localhost:3001/api node seed-data.js for local testing
const API_URL = process.env.API_URL || 'https://flowops-backend.azurewebsites.net/api';
async function seedData() {
console.log('🌱 Seeding FlowOps database...\n');
// 1. Register test users
console.log('1. Creating test users...');
const users = [
{ name: 'Demo User', email: 'demo@flowops.com', password: 'Demo123!@#', role: 'admin' },
{ name: 'Alice Developer', email: 'alice@flowops.com', password: 'Password123!', role: 'developer' },
{ name: 'Bob Manager', email: 'bob@flowops.com', password: 'Password123!', role: 'manager' },
{ name: 'Charlie QA', email: 'charlie@flowops.com', password: 'Password123!', role: 'qa' }
];
const createdUsers = [];
for (const user of users) {
try {
const registerRes = await fetch(`${API_URL}/auth/register`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(user)
});
const registerData = await registerRes.json();
if (registerData.success || registerData.token) {
console.log(` ✅ User created: ${user.name}`);
createdUsers.push({ ...user, _id: registerData.user ? registerData.user.id : null });
} else {
console.log(` ⚠️ User ${user.name}: ${registerData.message || 'might already exist'}`);
}
} catch (e) {
console.log(` ❌ Failed to create user ${user.name}: ${e.message}`);
}
}
// 2. Login to get token
console.log('2. Logging in...');
const loginRes = await fetch(`${API_URL}/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: 'demo@flowops.com',
password: 'Demo123!@#'
})
});
const loginData = await loginRes.json();
if (!loginData.token) {
console.log('❌ Login failed:', loginData);
return;
}
console.log(' Token received: ✅\n');
const token = loginData.token;
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
};
// 3. Create sample projects
console.log('3. Creating sample projects...');
const projects = [
{
name: 'E-Commerce Platform',
description: 'Développement d\'une plateforme e-commerce complète avec panier, paiement et gestion des commandes.',
status: 'in_progress'
},
{
name: 'Mobile Banking App',
description: 'Application mobile de banking avec authentification biométrique et transferts en temps réel.',
status: 'planned'
},
{
name: 'CRM Dashboard',
description: 'Tableau de bord CRM pour la gestion des clients, leads et opportunités commerciales.',
status: 'in_progress'
}
];
const createdProjects = [];
for (const project of projects) {
const res = await fetch(`${API_URL}/projects`, {
method: 'POST',
headers,
body: JSON.stringify(project)
});
const data = await res.json();
if (data.data || data._id) {
createdProjects.push(data.data || data);
console.log(` ✅ Created: ${project.name}`);
} else {
console.log(` ⚠️ ${project.name}:`, data.message || 'already exists');
}
}
if (createdProjects.length === 0) {
console.log('\n No new projects created. Fetching existing...');
const existingRes = await fetch(`${API_URL}/projects`, { headers });
const existingData = await existingRes.json();
if (existingData.data) {
createdProjects.push(...existingData.data.slice(0, 3));
}
}
// 3.5 Create Teams
console.log('\n3.5. Creating teams for first project...');
if (createdProjects.length > 0) {
const firstProject = createdProjects[0];
const projectId = firstProject._id || firstProject.id;
const teams = [
{ name: 'Frontend Team', description: 'Responsible for all UI/UX development', type: 'development' },
{ name: 'Backend Team', description: 'API and Database management', type: 'development' },
{ name: 'QA Team', description: 'Quality Assurance and Testing', type: 'qa' }
];
for (const team of teams) {
try {
// Create team using project-scoped URL
const res = await fetch(`${API_URL}/projects/${projectId}/teams`, {
method: 'POST',
headers,
body: JSON.stringify(team)
});
const data = await res.json();
if (data.success && data.data) {
console.log(` ✅ Created Team: ${team.name}`);
const teamId = data.data._id;
// Add members to team (randomly assign users)
// We need to fetch all users first to get their IDs correctly
const usersRes = await fetch(`${API_URL}/users`, { headers });
const usersData = await usersRes.json();
const allUsers = usersData.data || [];
if (allUsers.length > 0) {
// Assign random users to this team
const membersToAdd = allUsers
// .filter(u => u.email !== 'demo@flowops.com') // Optional
.sort(() => 0.5 - Math.random())
.slice(0, 2);
for (const member of membersToAdd) {
try {
await fetch(`${API_URL}/teams/${teamId}/members`, {
method: 'POST',
headers,
body: JSON.stringify({ userId: member._id, role: 'member' })
});
console.log(` 👤 Added ${member.name} to ${team.name}`);
} catch (err) {
// Member might already be in team
}
}
}
} else {
console.log(` ⚠️ Team ${team.name}: ${data.message || 'might already exist'}`);
}
} catch (e) {
console.log(` ❌ Failed to create team ${team.name}: ${e.message}`);
}
}
} else {
console.log(' ⚠️ No projects available to assign teams to.');
}
// 4. Create sample tasks for each project
console.log('\n4. Creating sample tasks...');
const taskTemplates = [
// To Do
{ title: 'Setup project structure', status: 'todo', priority: 'high', type: 'task', storyPoints: 5 },
{ title: 'Design database schema', status: 'todo', priority: 'highest', type: 'story', storyPoints: 8 },
{ title: 'Create wireframes', status: 'todo', priority: 'medium', type: 'task', storyPoints: 3 },
{ title: 'Write API documentation', status: 'todo', priority: 'low', type: 'task', storyPoints: 2 },
// Doing (In Progress)
{ title: 'Implement user authentication', status: 'doing', priority: 'highest', type: 'story', storyPoints: 8 },
{ title: 'Build REST API endpoints', status: 'doing', priority: 'high', type: 'task', storyPoints: 5 },
{ title: 'Create React components', status: 'doing', priority: 'medium', type: 'task', storyPoints: 5 },
// Review
{ title: 'Code review for login feature', status: 'review', priority: 'high', type: 'task', storyPoints: 2 },
{ title: 'Security audit implementation', status: 'review', priority: 'highest', type: 'bug', storyPoints: 3 },
// Done
{ title: 'Initial project setup', status: 'done', priority: 'high', type: 'task', storyPoints: 3 },
{ title: 'Configure CI/CD pipeline', status: 'done', priority: 'medium', type: 'story', storyPoints: 5 },
{ title: 'Setup Docker containers', status: 'done', priority: 'medium', type: 'task', storyPoints: 3 }
];
for (const project of createdProjects) {
const projectId = project._id || project.id;
if (!projectId) continue;
console.log(` 📁 Adding tasks to: ${project.name} (ID: ${projectId})`);
for (const task of taskTemplates) {
try {
const res = await fetch(`${API_URL}/projects/${projectId}/tasks`, {
method: 'POST',
headers,
body: JSON.stringify({
...task,
description: `Task: ${task.title} for project ${project.name}`
})
});
const data = await res.json();
if (data.success && data.data) {
console.log(` ✅ ${task.title} (${data.data.taskKey})`);
} else {
console.log(` ❌ ${task.title}: ${data.message || JSON.stringify(data)}`);
}
} catch (e) {
console.log(` ❌ Failed: ${task.title} - ${e.message}`);
}
}
}
// 5. Create sample sprints for first project
console.log('\n5. Creating sample sprints...');
if (createdProjects.length > 0) {
const project = createdProjects[0];
const projectId = project._id || project.id;
// Refresh tasks list for this project to ensure we have all tasks (newly created or existing)
console.log(' 🔄 Fetching latest tasks for project...');
let projectTasks = [];
try {
const tasksRes = await fetch(`${API_URL}/projects/${projectId}/tasks`, { headers });
const tasksData = await tasksRes.json();
projectTasks = tasksData.data || [];
console.log(` ✅ Found ${projectTasks.length} tasks available for sprints`);
} catch (e) {
console.log(' ⚠️ Failed to fetch tasks:', e.message);
}
const today = new Date();
const twoWeeksFromNow = new Date(today.getTime() + 14 * 24 * 60 * 60 * 1000);
const fourWeeksFromNow = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000);
const sprints = [
{
name: 'Sprint 1 - Foundation',
goal: 'Set up project foundation, authentication, and basic API structure',
startDate: today.toISOString(),
endDate: twoWeeksFromNow.toISOString()
},
{
name: 'Sprint 2 - Core Features',
goal: 'Implement core business features and UI components',
startDate: twoWeeksFromNow.toISOString(),
endDate: fourWeeksFromNow.toISOString()
}
];
const createdSprints = [];
for (const sprint of sprints) {
try {
const res = await fetch(`${API_URL}/projects/${projectId}/sprints`, {
method: 'POST',
headers,
body: JSON.stringify(sprint)
});
const data = await res.json();
if (data.success && data.data) {
createdSprints.push(data.data);
console.log(` ✅ Created: ${sprint.name}`);
} else {
console.log(` ❌ ${sprint.name}: ${data.message || JSON.stringify(data)}`);
}
} catch (e) {
console.log(` ❌ Failed: ${sprint.name} - ${e.message}`);
}
}
// Start the first sprint and add tasks to it
if (createdSprints.length > 0) {
const firstSprint = createdSprints[0];
// Add some tasks to the sprint
const taskIdsForSprint = projectTasks.slice(0, 6).map(t => t._id);
if (taskIdsForSprint.length > 0) {
try {
await fetch(`${API_URL}/sprints/${firstSprint._id}/tasks`, {
method: 'POST',
headers,
body: JSON.stringify({ taskIds: taskIdsForSprint })
});
console.log(` ✅ Added ${taskIdsForSprint.length} tasks to Sprint 1`);
} catch (e) {
console.log(` ❌ Failed to add tasks to sprint`);
}
}
// Start the sprint
try {
await fetch(`${API_URL}/sprints/${firstSprint._id}/start`, {
method: 'PUT',
headers
});
console.log(` ✅ Started Sprint 1`);
} catch (e) {
console.log(` ❌ Failed to start sprint: ${e.message}`);
}
}
}
console.log('\n✅ Seeding complete!');
console.log('\n📋 Login credentials:');
console.log(' Email: demo@flowops.com');
console.log(' Password: Demo123!@#');
console.log('\n🌐 URL: https://flowops-frontend.azurewebsites.net');
}
seedData().catch(console.error);