Commiting stop based booking

This commit is contained in:
Muluhabt
2026-07-23 20:11:11 +03:00
parent 8bba882710
commit 64e1130f7d
14 changed files with 354 additions and 147 deletions

View File

@@ -23,6 +23,17 @@ export const IDS = {
/** Route stop distances (km from origin). A=0, B=100, C=250 → A→B is 100km, A→C is 250km. */
export const DISTANCE = { A: 0, B: 100, C: 250 } as const;
/**
* Optional per-stop check-in-cutoff/travel-time overrides, keyed by station label (A/B/C).
* Lets a spec seed a distinct `checkinMinutesBefore` override and/or `travelMinutesToStop`
* per stop without changing the zero-arg call sites the other specs rely on.
*/
export interface RouteStopOverrides {
A?: { checkinMinutesBefore?: number; travelMinutesToStop?: number };
B?: { checkinMinutesBefore?: number; travelMinutesToStop?: number };
C?: { checkinMinutesBefore?: number; travelMinutesToStop?: number };
}
/**
* FX rate chosen so the seat-class distance formula (which multiplies an ETB/km rate by the
* USD→ETB rate — see fare-engine.service.ts:157) yields whole ETB-minor amounts. 100 makes the
@@ -45,7 +56,7 @@ export async function truncateAllPassenger(prisma: PrismaClient): Promise<void>
}
/** Insert the deterministic core graph. Call after truncateAllPassenger. */
export async function seedCore(prisma: PrismaClient): Promise<void> {
export async function seedCore(prisma: PrismaClient, stopOverrides: RouteStopOverrides = {}): Promise<void> {
const past = new Date("2020-01-01T00:00:00.000Z");
await prisma.coachType.create({
@@ -103,9 +114,9 @@ export async function seedCore(prisma: PrismaClient): Promise<void> {
active: true,
stops: {
create: [
{ stationId: IDS.stationA, sequence: 1, distanceKm: DISTANCE.A },
{ stationId: IDS.stationB, sequence: 2, distanceKm: DISTANCE.B },
{ stationId: IDS.stationC, sequence: 3, distanceKm: DISTANCE.C },
{ stationId: IDS.stationA, sequence: 1, distanceKm: DISTANCE.A, ...stopOverrides.A },
{ stationId: IDS.stationB, sequence: 2, distanceKm: DISTANCE.B, ...stopOverrides.B },
{ stationId: IDS.stationC, sequence: 3, distanceKm: DISTANCE.C, ...stopOverrides.C },
],
},
},
@@ -122,7 +133,7 @@ export async function seedCore(prisma: PrismaClient): Promise<void> {
}
/** Convenience: reset + seed in one call. */
export async function resetAndSeedCore(prisma: PrismaClient): Promise<void> {
export async function resetAndSeedCore(prisma: PrismaClient, stopOverrides: RouteStopOverrides = {}): Promise<void> {
await truncateAllPassenger(prisma);
await seedCore(prisma);
await seedCore(prisma, stopOverrides);
}