Skip to content

Refactor Phase 4B: Core Buisness -> Trips and Packages - #56

Closed
1mimhe wants to merge 8 commits into
masterfrom
refactor/phase-4-turf
Closed

1mimhe wants to merge 8 commits into
masterfrom
refactor/phase-4-turf

Conversation

@1mimhe

@1mimhe 1mimhe commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Phase 4 core-business pricing refactor:

- pricing.engine.ts: pure pipeline extracted verbatim from the legacy PricingService (identical arithmetic order and float behavior).

- strategies/: distance-tier, weight, special-handling, city-premium, deviation-cost, earnings + pricing-factory wiring all PRICING_* config.

- B-10 fix: tier capacities derive from cumulative bounds (upToKm - previousUpToKm) with no hand-tuned +1 constant; proven byte-identical to legacy output by a 500-check parity harness against the golden capture.

- pricing.service.ts: slim DI facade preserving the public API consumed by package.service (calculateSuggestedPrice / calculateTransporterEarnings / calculateDeviationCost / calculateDistanceCost).

- Table-driven specs per strategy + golden-equality engine spec (default variant, bit-exact floats) + facade spec.

Verification: tsc clean; full suite 53/53 suites, 401/401 tests; pricing 9/9 suites, 91/91 tests.
…yzer with parity specs

- Add pure MatchingScorer, buildTripCandidateWhere and CorridorAnalyzer
  under src/modules/package/matching/ (moved verbatim, no behavior change)
- Slim MatchingService to orchestration: delegates scoring/analysis,
  Nest Logger instead of console.error, ConfigKey.Pricing.CorridorWidth
- Fix TurfService console.error -> Logger (fallback path now covered)
- Add table-driven specs + match fixtures; extend matching.service.spec
  (Logger skip, ConfigKey read/default, default-param paths)

Verification: tsc clean, 56 suites / 437 tests green, scoped eslint 0 errors.
No API-visible change (BREAKING 4.0 stands).
- application/trip.service.ts: CRUD, getMultipleById, status lifecycle
  (toggle/start/pickup/delivery/finish)
- domain/trip-request.service.ts: updateRequest accept/reject,
  getAllTripRequests, getAllMatchedRequests
- domain/trip-tracking.service.ts: notes, tracking, rateTrip, directions
- domain/matched-route-sorter.ts: extracted route-ordering helper
- All writes via TransactionRunner; error mapping left to the global
  filter (no formatPrismaError boilerplate)
- Fixes (same behavior otherwise): reject branch, update/delete and
  start/pickup/delivery helpers now run inside the tx (used root client
  or default-prisma before); startTrip tracking joins the tx
- Deviations recorded: no cancelRequest exists (delete + reject cover it;
  trip module has no session mutation, A-4 already clean); rateTrip has
  no financial interplay (escrow accept=non-fatal, delivery=fatal kept);
  run() used everywhere (runIsolated deferred — no retry policy)
- Controller routes/method names unchanged (delegates to 3 services);
  package.service import repointed to new path

Verification: tsc clean, 59 suites / 453 tests green, scoped eslint
0 errors. No API-visible change.
…ices

- application/package.service.ts: CRUD, getMatchedTrips orchestration,
  presigned-URL helper (Logger, no JsonArray import — B-9)
- domain/recipient.service.ts: createRecipient (single TransactionRunner
  op) + getAllRecipients
- domain/package-request.service.ts: createRequest, list, updateRequest
  (=cancel) with session isRequestSent mutation AFTER commit (A-4: Redis
  session is not transactional with Postgres; new tests prove the flag
  is untouched when the tx fails)
- domain/tracking.service.ts: getTrackingByCode with sender phone masked
  as +98•••••123 (S-8; public endpoint — BREAKING 4.1; transporter phone
  left as residual follow-up)
- common/utils/phone.ts maskPhoneNumber helper + spec
- All writes via TransactionRunner; update/delete fixed to write through
  tx (used root client inside the transaction)
- Controller routes/method names unchanged (delegates to 4 services)

Verification: tsc clean, 63 suites / 470 tests green, scoped eslint
0 errors. API-visible: tracking sender phone now masked.
- turf.service.geometry.spec.ts: real @turf/turf (no mocks) — point/route
  construction, on/off-route distances, degenerate single-point fallback,
  direction checks, array/Map route sorting incl. empty/single inputs.
  Found via real turf: checkDirectionCompatibility compares segment
  indices, so 2-vertex routes always read 0 > 0 (documented in spec).
- notification-messages.spec.ts: locks placeholder behavior (templates
  carry # but substitution targets {key}, so # is kept; missing keys
  untouched). No behavior change.
- prisma/repositories/city.repository.ts (pulled forward from Phase 5):
  tx-aware findCityOrThrow/findCityWithProvince, provided by PrismaModule
- Migrated city reads in map.getIntermediateCitiesWithIds, trip.create
  and recipient.createRecipient onto the repository (tx passed through
  inside transactions); MapService no longer depends on PrismaService.
  Verified trip/package paths never touched MapService->Prisma directly.

Verification: tsc clean, 66 suites / 492 tests green, scoped eslint
0 errors (map.service console/any warnings pre-existing, Phase 5 scope).
No API-visible change.
@1mimhe 1mimhe closed this Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant