mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 00:50:56 +00:00
seed vehicle
This commit is contained in:
42
apps/edr-freight-api/src/scripts/seed-edr-trucks.ts
Normal file
42
apps/edr-freight-api/src/scripts/seed-edr-trucks.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { AppDataSource } from '../data-source';
|
||||
import { EdrTruckFleetSeeder } from '../seed/edr-truck-fleet.seeder';
|
||||
|
||||
/**
|
||||
* Seeds the 62-truck EDR fleet used by first-mile / last-mile.
|
||||
*
|
||||
* The seeder is idempotent (`ON CONFLICT (plate_number) DO NOTHING`), so a
|
||||
* re-run will NOT overwrite a truck whose rate was corrected by hand — the
|
||||
* seeded rate is a placeholder and is meant to be replaced.
|
||||
*/
|
||||
async function seedEdrTrucks() {
|
||||
await AppDataSource.initialize();
|
||||
|
||||
try {
|
||||
await new EdrTruckFleetSeeder(AppDataSource).run();
|
||||
|
||||
const summary = await AppDataSource.query(`
|
||||
SELECT
|
||||
COUNT(*)::int AS trucks,
|
||||
COUNT(*) FILTER (WHERE status = 'ACTIVE')::int AS active,
|
||||
COUNT(*) FILTER (WHERE availability = 'FREE')::int AS free,
|
||||
COUNT(*) FILTER (WHERE price_per_km > 0)::int AS priced,
|
||||
COUNT(*) FILTER (WHERE price_per_km IS NULL OR price_per_km <= 0)::int AS unpriced,
|
||||
MIN(price_per_km)::text AS min_rate,
|
||||
MAX(price_per_km)::text AS max_rate
|
||||
FROM freight.vehicles
|
||||
WHERE vehicle_type = 'TRUCK';
|
||||
`);
|
||||
|
||||
console.table(summary);
|
||||
console.log(
|
||||
'Seeded EDR truck fleet. NOTE: price_per_km is DEMO DATA — replace with the real tariff before billing.',
|
||||
);
|
||||
} finally {
|
||||
await AppDataSource.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
seedEdrTrucks().catch((error) => {
|
||||
console.error('Failed to seed EDR truck fleet:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user