Repository navigation
Refactor Phase 4: Core Buisness: Packages, Trips and Turf modules - #57
Merged
Merged
Conversation
- 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
added a commit
that referenced
this pull request
Oct 4, 2026
* refactor(infra): ports + S3/SMS/Maps adapters, delete S3Service/SmsService - src/infra/ports/: StoragePort/SmsPort/MapsPort (plain interfaces) + PORTS.* tokens, bound in S3Module/SmsModule/MapModule - S3StorageAdapter/NeshanMapsAdapter/SmsAdapter moved verbatim (same URLs, headers, payloads, thrown messages; console.* -> Logger). Deviation: SMS requests retry once on network/5xx, then throw the legacy message. CodeGeneratorPort skipped (codes.ts already pure/tested). - Deleted s3.service.ts + sms.service.ts; migrated all importers (s3.controller, vehicle, dashboard, package app/tracking, trip-request, user interim port, otp) to the tokens; dropped dead PrismaModule import from S3Module. MapService is now orchestration over MapsPort + CityRepository (no PrismaService, no Neshan HTTP). - Docs note: BREAKING-CHANGES 4.1 (tracking phone masked +98LAST3) is applied in master via #57 — the pending entry predates the merge. Verification: tsc clean, affected 28 suites / 256 tests green, scoped eslint 0 errors. No API-visible change (SMS retry is timing-only). * refactor(map): extract route-filters, delegate HTTP to MapsPort - map/route-filters.ts: extractSignificantPoints + haversineDistance moved verbatim as exported pure helpers (threshold constant named); specs cover origin inclusion, وارد/priority/long-distance selection, min-distance dedup (first candidate passes: lastPoint starts undefined — locked), multi-leg accumulation, haversine zero/1-degree/symmetry - MapService keeps orchestration (intermediate-cities flow, delay) and delegates calculateDistance/reverseGeocode/getDirections to MapsPort; typed unknown-catch handling removes no-unsafe-* warnings on touched paths (2 intentional no-console warnings remain in orchestration) Verification: tsc clean, map 3 suites / 14 tests green, scoped eslint 0 errors. No API-visible change. * refactor(financial): split into WalletService + EscrowService + facade - domain/wallet.service.ts: getWallet (tx-aware) + addFunds via TransactionRunner; BigInt serialized only via common/utils/money.ts formatMoney (tested: zero/negative/large/null) - domain/escrow.service.ts: createEscrow/releaseEscrow/ addFundsAndCreateEscrow; release joins the caller tx (fatal, as before), creation stays non-fatal at the trip call-site - financial.service.ts is now a thin facade (same 5 methods) so the controller and trip/package importers are untouched - Preserved quirks (documented, not fixed): Int/BigInt column mismatch, number-domain commission math, totalSpent never incremented, non-atomic addFundsAndCreateEscrow, raw Error on missing platform wallet (correctly 500s via the filter) Verification: tsc clean, financial 5 suites / 23 tests green, scoped eslint 0 errors. No API-visible change. * refactor(modules): clean user/notification/support/address/dashboard/vehicle + S3 size limit - user: drop formatPrismaError wrappers; fix licenseNumber branch writing licenseStatus (was nationalIdStatus twice — spec names already expected the fix); old error-mapping tests now assert raw propagation - notification: getAll via TransactionRunner (reads through tx), unreadCount query + GET /notification/unread-count route - support: runner + tx-through getTransporter; updateTransporter- Verification throws 404 on missing verificationStatusId (was 500) — BREAKING 5.1; new NotFoundMessages.VerificationStatus - address: runner + CityRepository, tx-through create (was root client); dashboard: drop filter wrapper (outputs byte-identical, locked by new transporter/sender/admin specs); vehicle: runner + Logger (was console) - S3: MAX_UPLOAD_SIZE_MB env (default 10) + optional declared `size` on all 7 presign endpoints, 400 over the limit — BREAKING 5.2; new s3.controller.spec; S3Service->port migration is internal only (5.3) - controllers: route-level delegation specs for financial/user/vehicle/ address/support/dashboard/notification/map Verification: tsc clean, 73 suites / 579 tests green, scoped eslint 0 errors. API-visible: 5.1, 5.2 (5.3 internal). * chore(config): tslib/importHelpers, jest dto excludes, ignore coverage txts tslib + importHelpers for helper dedup; jest collectCoverageFrom now excludes sibling *.dto.ts and *.d.ts (DTO decorator branches aren't logic); coverage-*.txt ignored. tsc 0. * test(infra): cover adapter branches — custom expiry, otp 4xx, explicit routing S3 get custom expiry, SmsAdapter sendOtp 4xx no-retry, MapsAdapter calculateDistance with explicit vehicle/trip/waypoints. 28 tests green, scoped eslint 0 errors. * refactor(map): Logger instead of console + intermediate-cities branch specs Last console.* in phase scope replaced with injected Logger (B-4); intermediate-cities branch specs (coords delegation, empty legs, dedupe, non-Error rejections). Map specs green. * refactor(notification): add Logger + default-pagination spec Logger instance for Phase 5 Task 3 compliance (no log sites — global filter owns errors); default-pagination spec covers page/limit defaults. Notification specs green. * test(modules): branch coverage for address/dashboard/financial/s3/vehicle Delegation specs for update routes, non-highlighted search, null-sum escrow, wallet-null platform guard, default-vs-tx reads, presign key matrix + size-limit 400, S3 presigned-URL failure blanks, new s3.dto.spec (filename/size validation; fixes no-unnecessary-type-assertion). Full suite: 74 suites / 611 tests green, tsc 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.