mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 22:25:42 +00:00
Fix price inconsistency
This commit is contained in:
@@ -595,10 +595,20 @@ export class SearchService {
|
||||
});
|
||||
const freeChildrenAllowed = groupFare.freeChildrenCount;
|
||||
|
||||
// Calculate per-passenger fare rate (engine called with 1 adult, 0 children — pure rate lookup)
|
||||
// Pre-compute isFree per passenger index synchronously so the race-free
|
||||
// counter assignment isn't corrupted by concurrent Promise.all resolution.
|
||||
let freeChildrenUsed = 0;
|
||||
const isFreeByIndex = categorised.map(p => {
|
||||
if (p.category === 'CHILD' && freeChildrenUsed < freeChildrenAllowed) {
|
||||
freeChildrenUsed++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Calculate per-passenger fare rate (engine called with 1 adult, 0 children — pure rate lookup)
|
||||
const passengerLines = await Promise.all(
|
||||
categorised.map(async (p) => {
|
||||
categorised.map(async (p, idx) => {
|
||||
const fare = await this.fareEngine.calculate({
|
||||
routeId: schedule.routeId!,
|
||||
originStationId: dto.originStationId,
|
||||
@@ -610,8 +620,7 @@ export class SearchService {
|
||||
childCount: 0,
|
||||
});
|
||||
|
||||
const isFree = p.category === 'CHILD' && freeChildrenUsed < freeChildrenAllowed;
|
||||
if (isFree) freeChildrenUsed++;
|
||||
const isFree = isFreeByIndex[idx];
|
||||
|
||||
const fareMinor = isFree
|
||||
? fare.premiumPerPassenger + fare.insurancePerPassenger
|
||||
|
||||
Reference in New Issue
Block a user