mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
seed vehicle
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
"test": "jest",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"seed:wagons": "ts-node -r tsconfig-paths/register src/scripts/seed-edr-wagons.ts",
|
||||
"seed:trucks": "ts-node -r tsconfig-paths/register src/scripts/seed-edr-trucks.ts",
|
||||
"type-check": "tsc --noEmit",
|
||||
"seed:demo-scheduling": "ts-node -r tsconfig-paths/register src/scripts/seed-demo-scheduling.ts",
|
||||
"seed:freight-demo": "ts-node -r tsconfig-paths/register src/scripts/seed-freight-demo.ts",
|
||||
|
||||
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);
|
||||
});
|
||||
@@ -34,6 +34,16 @@ const EDR_TRUCK_FLEET: ReadonlyArray<readonly [string, string]> = [
|
||||
/** Fleet sequence numbers (1-based) that are 20ft-only. 6 of 62 — fill once confirmed. */
|
||||
const TWENTY_FT_SEQS = new Set<number>();
|
||||
|
||||
/**
|
||||
* PLACEHOLDER haulage rate, ETB per km — NOT a real EDR tariff.
|
||||
*
|
||||
* First/last-mile billing is `distance × pricePerKm`, and a truck with no rate
|
||||
* is refused at assignment, which would leave the whole demo flow unusable. This
|
||||
* exists so the flow is clickable end to end; every amount it produces is
|
||||
* fiction. Replace per truck in the fleet UI before anything bills for real.
|
||||
*/
|
||||
const PLACEHOLDER_PRICE_PER_KM = 50;
|
||||
|
||||
@Injectable()
|
||||
export class EdrTruckFleetSeeder {
|
||||
private readonly logger = new Logger(EdrTruckFleetSeeder.name);
|
||||
@@ -50,7 +60,7 @@ export class EdrTruckFleetSeeder {
|
||||
const columns = [
|
||||
'code', 'plate_number', 'registration_number', 'power_plate_no', 'trailer_plate_no',
|
||||
'vehicle_type', 'manufacturer', 'model', 'year', 'fuel_type', 'capacity',
|
||||
'status', 'ownership', 'currency', 'description',
|
||||
'status', 'ownership', 'currency', 'price_per_km', 'description',
|
||||
];
|
||||
|
||||
const rows: unknown[][] = EDR_TRUCK_FLEET.map(([power, trailer], i) => {
|
||||
@@ -71,7 +81,9 @@ export class EdrTruckFleetSeeder {
|
||||
'ACTIVE',
|
||||
'EDR',
|
||||
'ETB',
|
||||
`EDR-owned container truck configured for ${ft} containers.`,
|
||||
PLACEHOLDER_PRICE_PER_KM,
|
||||
`EDR-owned container truck configured for ${ft} containers. ` +
|
||||
`Rate ${PLACEHOLDER_PRICE_PER_KM} ETB/km is DEMO DATA — replace with the real tariff.`,
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user