mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 09:30:59 +00:00
Adding all the tests and fixes to the passengers app
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user