freightdesk/webapp/scripts/seed-demo.js
FreightDesk 9b5e568e72
Some checks are pending
FreightDesk CI/CD / Lint & Test (push) Waiting to run
FreightDesk CI/CD / Build Docker Image (push) Blocked by required conditions
FreightDesk CI/CD / Deploy to Coolify (push) Blocked by required conditions
[OWL] Bug fixes + seed data + bulk parser route
Fixes:
- Negotiate route: added auth check (only shipper or bidder can negotiate)
- Negotiate route: added notification to other party
- All payment views: removed /100 division (amounts stored in rupees, not paise)
- Migration 006: updated platform_config seed values to rupees
- Migration 007: added current_lat/current_lng columns to vehicles table
- Added bulk-parser route to marketplace.js
- Added Bulk WhatsApp Parser link to portal sidebar

Seed Data:
- scripts/seed-demo.js: 5 shippers, 5 drivers, 8 loads, sample bids
- Idempotent: skips if data already exists
2026-06-08 02:16:02 +00:00

138 lines
8.1 KiB
JavaScript

#!/usr/bin/env node
/**
* FreightDesk — Demo Seed Data Script
* Run: node scripts/seed-demo.js
*
* Creates demo shippers, drivers, loads, and bids for testing.
* Requires SUPABASE_URL and SUPABASE_SERVICE_KEY in environment.
*/
const supabase = require('../src/services/supabase');
const DEMO_SHIPPERS = [
{ name: 'Kahn Transport', phone: '+919876543210', email: 'kahn@example.com', company_name: 'Kahn Transport Pvt Ltd', city: 'Kochi', state: 'Kerala', address: 'MG Road, Ernakulam', is_verified: true },
{ name: 'Agarwal Logistics', phone: '+918765432109', email: 'agarwal@example.com', company_name: 'Agarwal Trading Co', city: 'Bangalore', state: 'Karnataka', address: 'KR Market', is_verified: true },
{ name: 'Rajesh Freight', phone: '+917654321098', email: 'rajesh@example.com', city: 'Chennai', state: 'Tamil Nadu', address: 'T Nagar', is_verified: true },
{ name: 'Sharma Carriers', phone: '+916543210987', email: 'sharma@example.com', company_name: 'Sharma & Sons', city: 'Mumbai', state: 'Maharashtra', address: 'Andheri', is_verified: true },
{ name: 'VIP Logistics', phone: '+915432109876', email: 'vip@example.com', city: 'Hyderabad', state: 'Telangana', address: 'Banjara Hills', is_verified: false },
];
const DEMO_DRIVERS = [
{ driver_name: 'Suresh Kumar', phone: '+919988776655', vehicle_number: 'KL 01 AB 1234', vehicle_type: '14ft', capacity_tons: 7, city: 'Kochi', state: 'Kerala', is_verified: true },
{ driver_name: 'Ramesh Singh', phone: '+918877665544', vehicle_number: 'KA 05 CD 5678', vehicle_type: '17ft', capacity_tons: 9, city: 'Bangalore', state: 'Karnataka', is_verified: true },
{ driver_name: 'Abdul Rahman', phone: '+917766554433', vehicle_number: 'TN 09 EF 9012', vehicle_type: '19ft', capacity_tons: 12, city: 'Chennai', state: 'Tamil Nadu', is_verified: true },
{ driver_name: 'Prakash Yadav', phone: '+916655443322', vehicle_number: 'MH 12 GH 3456', vehicle_type: '20ft', capacity_tons: 14, city: 'Mumbai', state: 'Maharashtra', is_verified: true },
{ driver_name: 'Venkat Rao', phone: '+915544332211', vehicle_number: 'TS 08 IJ 7890', vehicle_type: '17ft', capacity_tons: 9, city: 'Hyderabad', state: 'Telangana', is_verified: false },
];
const DEMO_LOADS = [
{ from_city: 'Bangalore', to_city: 'Kochi', load_type: 'ftl', weight_kg: 8000, material_type: 'Electronics', budget_min: 25000, budget_max: 35000, pickup_date: '2026-02-15', delivery_date: '2026-02-17' },
{ from_city: 'Chennai', to_city: 'Mumbai', load_type: 'ftl', weight_kg: 12000, material_type: 'Machine Parts', budget_min: 45000, budget_max: 55000, pickup_date: '2026-02-16', delivery_date: '2026-02-19' },
{ from_city: 'Mumbai', to_city: 'Hyderabad', load_type: 'ftl', weight_kg: 10000, material_type: 'Chemicals', budget_min: 30000, budget_max: 40000, pickup_date: '2026-02-17', delivery_date: '2026-02-20' },
{ from_city: 'Hyderabad', to_city: 'Bangalore', load_type: 'ftl', weight_kg: 9000, material_type: 'Textiles', budget_min: 20000, budget_max: 28000, pickup_date: '2026-02-18', delivery_date: '2026-02-21' },
{ from_city: 'Kochi', to_city: 'Chennai', load_type: 'ftl', weight_kg: 7000, material_type: 'Spices', budget_min: 18000, budget_max: 25000, pickup_date: '2026-02-19', delivery_date: '2026-02-22' },
{ from_city: 'Bangalore', to_city: 'Mumbai', load_type: 'ptl', weight_kg: 3000, material_type: 'Auto Parts', budget_min: 12000, budget_max: 18000, pickup_date: '2026-02-20', delivery_date: '2026-02-23' },
{ from_city: 'Delhi', to_city: 'Bangalore', load_type: 'ftl', weight_kg: 15000, material_type: 'Furniture', budget_min: 55000, budget_max: 70000, pickup_date: '2026-02-21', delivery_date: '2026-02-25' },
{ from_city: 'Chennai', to_city: 'Kochi', load_type: 'ftl', weight_kg: 6000, material_type: 'Tea', budget_min: 15000, budget_max: 22000, pickup_date: '2026-02-22', delivery_date: '2026-02-24' },
];
async function seed() {
console.log('🌱 Seeding FreightDesk demo data...\n');
// Check if already seeded
const { count: existingLoads } = await supabase.from('loads').select('*', { count: 'exact', head: true });
if (existingLoads > 0) {
console.log(`⚠️ Found ${existingLoads} existing loads. Skipping seed. (Delete manually to re-seed)`);
process.exit(0);
}
// Seed shippers
console.log('📦 Creating shippers...');
const { data: shippers, error: shipperError } = await supabase.from('shippers').insert(DEMO_SHIPPERS).select();
if (shipperError) { console.error('Shipper error:', shipperError); process.exit(1); }
console.log(`${shippers.length} shippers created`);
// Seed vehicles (drivers)
console.log('🚛 Creating drivers/vehicles...');
const driverRecords = DEMO_DRIVERS.map(d => ({
number: d.vehicle_number,
vehicle_type: d.vehicle_type,
capacity_tons: d.capacity_tons,
city: d.city,
state: d.state,
is_verified: d.is_verified,
driver_name: d.driver_name,
phone: d.phone,
}));
const { data: vehicles, error: vehicleError } = await supabase.from('vehicles').insert(driverRecords).select();
if (vehicleError) { console.error('Vehicle error:', vehicleError); process.exit(1); }
console.log(`${vehicles.length} drivers/vehicles created`);
// Seed loads
console.log('📋 Creating marketplace loads...');
const loadRecords = DEMO_LOADS.map((l, i) => ({
...l,
shipper_id: shippers[i % shippers.length]?.id,
status: 'pending lead',
is_open: true,
expires_at: new Date(Date.now() + 7 * 86400000).toISOString(),
views: Math.floor(Math.random() * 50),
pickup_address: 'Pickup location TBD',
delivery_address: 'Delivery location TBD',
}));
const { data: loads, error: loadError } = await supabase.from('loads').insert(loadRecords).select();
if (loadError) { console.error('Load error:', loadError); process.exit(1); }
console.log(`${loads.length} loads created`);
// Seed some bids
console.log('💰 Creating sample bids...');
const bidRecords = [];
for (const load of loads.slice(0, 4)) {
const numBids = Math.floor(Math.random() * 3) + 1;
for (let i = 0; i < numBids; i++) {
const vehicle = vehicles[i % vehicles.length];
const baseLoad = DEMO_LOADS[loads.indexOf(load)];
const bidAmount = baseLoad.budget_min + Math.floor(Math.random() * (baseLoad.budget_max - baseLoad.budget_min) * 0.3);
bidRecords.push({
load_id: load.id,
shipper_id: load.shipper_id,
driver_id: vehicle.id,
amount: bidAmount,
message: `Available for immediate pickup. ${vehicle.vehicle_type} truck. Contact: ${vehicle.phone}`,
status: 'pending',
});
}
}
if (bidRecords.length > 0) {
const { error: bidError } = await supabase.from('bids').insert(bidRecords);
if (bidError) { console.error('Bid error:', bidError); process.exit(1); }
console.log(`${bidRecords.length} bids created`);
}
// Ensure platform config
console.log('⚙️ Setting platform config...');
await supabase.from('platform_config').upsert([
{ key: 'escrow.platform_fee_percent', value: '5', description: 'Platform commission percentage' },
{ key: 'escrow.min_deposit_amount', value: '100', description: 'Minimum deposit in rupees' },
{ key: 'escrow.hold_period_hours', value: '72', description: 'Hours to hold funds after delivery' },
{ key: 'escrow.payout_min_amount', value: '500', description: 'Minimum payout in rupees' },
], { onConflict: 'key' });
console.log('\n✅ Seed complete!');
console.log('\n📊 Demo data:');
console.log(` ${shippers.length} shippers (${shippers.filter(s => s.is_verified).length} verified)`);
console.log(` ${vehicles.length} drivers (${vehicles.filter(v => v.is_verified).length} verified)`);
console.log(` ${loads.length} marketplace loads`);
console.log(` ${bidRecords.length} bids`);
console.log('\n🌐 Access the app:');
console.log(' Landing: http://localhost:3000/');
console.log(' Admin: http://localhost:3000/login');
console.log(' Marketplace: http://localhost:3000/marketplace');
console.log(' Portal: http://localhost:3000/portal');
process.exit(0);
}
seed().catch(err => {
console.error('❌ Seed failed:', err);
process.exit(1);
});