Files
vip-coordinator/populate-events-dynamic.js

218 lines
6.8 KiB
JavaScript

// Dynamic script to populate Events and Meetings for current VIPs in VIP Coordinator
const API_BASE = 'http://localhost:3000/api';
// Function to get all current VIPs and drivers
async function getCurrentData() {
try {
const [vipsResponse, driversResponse] = await Promise.all([
fetch(`${API_BASE}/vips`),
fetch(`${API_BASE}/drivers`)
]);
if (!vipsResponse.ok || !driversResponse.ok) {
throw new Error('Failed to fetch current data');
}
const vips = await vipsResponse.json();
const drivers = await driversResponse.json();
return { vips, drivers };
} catch (error) {
console.error('Error fetching current data:', error);
throw error;
}
}
// Function to add events for a specific VIP
async function addEventsForVip(vip, driverIndex, drivers) {
const assignedDriver = drivers[driverIndex % drivers.length];
const events = [];
// Different event templates based on VIP characteristics
if (vip.transportMode === 'flight') {
// Airport arrival event
events.push({
title: 'Arrival at DEN',
location: 'Denver International Airport',
startTime: '2025-06-26T09:00:00',
endTime: '2025-06-26T10:00:00',
type: 'transport',
assignedDriverId: assignedDriver.id,
description: `Airport pickup for ${vip.name}`
});
// Business meeting
events.push({
title: `Meeting with ${vip.organization} Partners`,
location: 'Denver Convention Center',
startTime: '2025-06-26T11:00:00',
endTime: '2025-06-26T12:30:00',
type: 'meeting',
assignedDriverId: assignedDriver.id,
description: `Strategic meeting for ${vip.name}`
});
}
// Lunch event (for all VIPs)
const restaurants = [
"Elway's Downtown",
"Linger",
"Guard and Grace",
"The Capital Grille",
"Mercantile Dining & Provision"
];
const lunchTitles = [
"Lunch with Board Members",
"Executive Lunch Meeting",
"Networking Lunch",
"Business Lunch",
"Partnership Lunch"
];
events.push({
title: lunchTitles[driverIndex % lunchTitles.length],
location: restaurants[driverIndex % restaurants.length],
startTime: '2025-06-26T13:00:00',
endTime: '2025-06-26T14:30:00',
type: 'meal',
assignedDriverId: assignedDriver.id,
description: `Fine dining experience for ${vip.name}`
});
// Afternoon event
const afternoonEvents = [
{ title: 'Presentation to Stakeholders', location: 'Denver Tech Center' },
{ title: 'Innovation Workshop', location: 'National Ballpark Museum' },
{ title: 'Industry Panel Discussion', location: 'Denver Art Museum' },
{ title: 'Strategic Planning Session', location: 'Wells Fargo Center' },
{ title: 'Product Demo Session', location: 'Colorado Convention Center' }
];
const afternoonEvent = afternoonEvents[driverIndex % afternoonEvents.length];
events.push({
title: afternoonEvent.title,
location: afternoonEvent.location,
startTime: '2025-06-26T15:00:00',
endTime: '2025-06-26T16:30:00',
type: 'event',
assignedDriverId: assignedDriver.id,
description: `Professional engagement for ${vip.name}`
});
// Evening event (for some VIPs)
if (driverIndex % 2 === 0) {
const dinnerEvents = [
{ title: 'VIP Reception', location: 'Four Seasons Hotel Denver' },
{ title: 'Awards Dinner', location: 'Denver Art Museum' },
{ title: 'Networking Dinner', location: 'Guard and Grace' },
{ title: 'Gala Event', location: 'Brown Palace Hotel' }
];
const dinnerEvent = dinnerEvents[driverIndex % dinnerEvents.length];
events.push({
title: dinnerEvent.title,
location: dinnerEvent.location,
startTime: '2025-06-26T18:30:00',
endTime: '2025-06-26T20:30:00',
type: 'event',
assignedDriverId: assignedDriver.id,
description: `Evening engagement for ${vip.name}`
});
}
// Add all events for this VIP
let successCount = 0;
for (const event of events) {
try {
const response = await fetch(`${API_BASE}/vips/${vip.id}/schedule`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(event)
});
if (response.ok) {
const result = await response.json();
console.log(`✅ Added "${event.title}" for ${vip.name}`);
successCount++;
} else {
const error = await response.text();
console.error(`❌ Failed to add "${event.title}" for ${vip.name}: ${error}`);
}
} catch (error) {
console.error(`❌ Error adding "${event.title}" for ${vip.name}:`, error);
}
}
return successCount;
}
// Main function to populate events for all VIPs
async function populateEventsForAllVips() {
console.log('🚀 Starting dynamic events population...\n');
// Check if API is available
try {
const healthCheck = await fetch(`${API_BASE}/health`);
if (!healthCheck.ok) {
console.error('❌ API is not responding. Make sure the backend is running on port 3000');
return;
}
} catch (error) {
console.error('❌ Cannot connect to API. Make sure the backend is running on port 3000');
return;
}
try {
// Get current VIPs and drivers
const { vips, drivers } = await getCurrentData();
console.log(`📋 Found ${vips.length} VIPs and ${drivers.length} drivers`);
console.log(`👥 VIPs: ${vips.map(v => v.name).join(', ')}`);
console.log(`🚗 Drivers: ${drivers.map(d => d.name).join(', ')}\n`);
if (vips.length === 0) {
console.error('❌ No VIPs found in the system');
return;
}
if (drivers.length === 0) {
console.error('❌ No drivers found in the system');
return;
}
let totalEvents = 0;
// Add events for each VIP
for (let i = 0; i < vips.length; i++) {
const vip = vips[i];
console.log(`\n📅 Creating events for ${vip.name} (${vip.organization})...`);
const eventsAdded = await addEventsForVip(vip, i, drivers);
totalEvents += eventsAdded;
// Small delay to avoid overwhelming the API
await new Promise(resolve => setTimeout(resolve, 100));
}
console.log(`\n✅ Dynamic events population complete!`);
console.log(`📊 Total events created: ${totalEvents}`);
console.log(`📈 Average events per VIP: ${(totalEvents / vips.length).toFixed(1)}`);
console.log('\n🎯 You can now:');
console.log('1. View all VIPs with schedules at http://localhost:5173/vips');
console.log('2. Check individual VIP schedules');
console.log('3. Manage driver assignments');
console.log('4. Test the schedule management features');
} catch (error) {
console.error('❌ Error during events population:', error);
}
}
// Run the script
populateEventsForAllVips().catch(console.error);