Adding all the tests and fixes to the passengers app

This commit is contained in:
Muluhabt
2026-07-21 15:26:29 +03:00
parent f2ae9c883f
commit 7e6778d025
3279 changed files with 117 additions and 12612 deletions

View File

@@ -23,8 +23,11 @@ export class FareEngineService {
if (!originStop) throw new BadRequestException('Origin station not found on this route');
if (!destStop) throw new BadRequestException('Destination station not found on this route');
if (originStop.sequence >= destStop.sequence)
throw new BadRequestException('Origin must come before destination in the route sequence');
// Origin and destination must be distinct stops, but EITHER direction is valid: a round-trip
// return leg traverses the same route high→low (e.g. C→A), so we price the segment by its
// absolute distance rather than rejecting the reverse order.
if (originStop.sequence === destStop.sequence)
throw new BadRequestException('Origin and destination must be different stops on this route');
const seatClass = await this.prisma.seatClass.findUnique({ where: { id: dto.seatClassId } });
if (!seatClass) throw new NotFoundException('Seat class not found');
@@ -43,8 +46,8 @@ export class FareEngineService {
},
}) ?? seatClass;
const totalDistanceKm = destStop.distanceKm! - originStop.distanceKm!;
if (totalDistanceKm < 0 || isNaN(totalDistanceKm))
const totalDistanceKm = Math.abs(destStop.distanceKm! - originStop.distanceKm!);
if (totalDistanceKm <= 0 || isNaN(totalDistanceKm))
throw new BadRequestException('Invalid distance calculation - check route stop distances');
const now = new Date();