mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 11:21:18 +00:00
Additional UAT issue resolutions
This commit is contained in:
@@ -144,22 +144,33 @@ export class GuestBookingService {
|
||||
});
|
||||
}
|
||||
|
||||
// Calculate fare
|
||||
const primaryNationality = passengersData[0]?.nationality;
|
||||
const baseFareMinor = await this.getBaseFare(
|
||||
dto.scheduleId,
|
||||
dto.seatClassId,
|
||||
segmentRoute,
|
||||
fullRoute,
|
||||
primaryNationality,
|
||||
dto.originStationId,
|
||||
dto.destinationStationId,
|
||||
);
|
||||
// Calculate fare — package bookings use the fixed tier price, bypassing the fare engine
|
||||
const isPackageOneway = !!dto.packageId && !!dto.priceTierId;
|
||||
let baseFareMinor: number;
|
||||
let paidChildrenCount: number;
|
||||
let childUnitFare: number;
|
||||
|
||||
if (isPackageOneway) {
|
||||
const tier = await this.prisma.packagePriceTier.findUniqueOrThrow({ where: { id: dto.priceTierId! } });
|
||||
baseFareMinor = tier.priceMinor;
|
||||
paidChildrenCount = childCount;
|
||||
childUnitFare = Math.round(baseFareMinor * 0.1);
|
||||
} else {
|
||||
const primaryNationality = passengersData[0]?.nationality;
|
||||
baseFareMinor = await this.getBaseFare(
|
||||
dto.scheduleId,
|
||||
dto.seatClassId,
|
||||
segmentRoute,
|
||||
fullRoute,
|
||||
primaryNationality,
|
||||
dto.originStationId,
|
||||
dto.destinationStationId,
|
||||
);
|
||||
paidChildrenCount = Math.max(0, childCount - 1);
|
||||
childUnitFare = baseFareMinor;
|
||||
}
|
||||
|
||||
const adultFareMinor = baseFareMinor * adultCount;
|
||||
const isPackageOneway = !!dto.packageId;
|
||||
const paidChildrenCount = isPackageOneway ? childCount : Math.max(0, childCount - 1);
|
||||
const childUnitFare = isPackageOneway ? Math.round(baseFareMinor * 0.1) : baseFareMinor;
|
||||
const childFareMinor = childUnitFare * paidChildrenCount;
|
||||
const totalBaseFareMinor = adultFareMinor + childFareMinor;
|
||||
|
||||
@@ -369,19 +380,34 @@ export class GuestBookingService {
|
||||
passengersData.push({ ...passenger, passengerName, dateOfBirth, category, verifaydaVerified, verifaydaData, nationality });
|
||||
}
|
||||
|
||||
// Calculate fares for both legs
|
||||
// Calculate fares for both legs — package bookings use the fixed tier price split across legs
|
||||
const returnSeatClassId = dto.returnSeatClassId || dto.seatClassId;
|
||||
const primaryNationality = passengersData[0]?.nationality;
|
||||
const isPackageRoundTrip = !!dto.packageId && !!dto.priceTierId;
|
||||
let outboundBaseFare: number;
|
||||
let returnBaseFare: number;
|
||||
let paidChildrenCount: number;
|
||||
let outboundChildUnitFare: number;
|
||||
let returnChildUnitFare: number;
|
||||
|
||||
const [outboundBaseFare, returnBaseFare] = await Promise.all([
|
||||
this.getBaseFare(dto.scheduleId, dto.seatClassId, outboundSegmentRoute, outboundFullRoute, primaryNationality, dto.originStationId, dto.destinationStationId),
|
||||
this.getBaseFare(dto.returnScheduleId, returnSeatClassId, returnSegmentRoute, returnFullRoute, primaryNationality, dto.returnOriginStationId, dto.returnDestinationStationId),
|
||||
]);
|
||||
|
||||
const isPackageRoundTrip = !!dto.packageId;
|
||||
const paidChildrenCount = isPackageRoundTrip ? childCount : Math.max(0, childCount - 1);
|
||||
const outboundChildUnitFare = isPackageRoundTrip ? Math.round(outboundBaseFare * 0.1) : outboundBaseFare;
|
||||
const returnChildUnitFare = isPackageRoundTrip ? Math.round(returnBaseFare * 0.1) : returnBaseFare;
|
||||
if (isPackageRoundTrip) {
|
||||
const tier = await this.prisma.packagePriceTier.findUniqueOrThrow({ where: { id: dto.priceTierId! } });
|
||||
// tier.priceMinor is the full round-trip price per adult; split evenly across legs
|
||||
const halfMinor = Math.round(tier.priceMinor / 2);
|
||||
outboundBaseFare = halfMinor;
|
||||
returnBaseFare = tier.priceMinor - halfMinor;
|
||||
paidChildrenCount = childCount;
|
||||
outboundChildUnitFare = Math.round(outboundBaseFare * 0.1);
|
||||
returnChildUnitFare = Math.round(returnBaseFare * 0.1);
|
||||
} else {
|
||||
const primaryNationality = passengersData[0]?.nationality;
|
||||
[outboundBaseFare, returnBaseFare] = await Promise.all([
|
||||
this.getBaseFare(dto.scheduleId, dto.seatClassId, outboundSegmentRoute, outboundFullRoute, primaryNationality, dto.originStationId, dto.destinationStationId),
|
||||
this.getBaseFare(dto.returnScheduleId, returnSeatClassId, returnSegmentRoute, returnFullRoute, primaryNationality, dto.returnOriginStationId, dto.returnDestinationStationId),
|
||||
]);
|
||||
paidChildrenCount = Math.max(0, childCount - 1);
|
||||
outboundChildUnitFare = outboundBaseFare;
|
||||
returnChildUnitFare = returnBaseFare;
|
||||
}
|
||||
const outboundTotalBase = outboundBaseFare * adultCount + outboundChildUnitFare * paidChildrenCount;
|
||||
const returnTotalBase = returnBaseFare * adultCount + returnChildUnitFare * paidChildrenCount;
|
||||
const combinedBaseFareMinor = outboundTotalBase + returnTotalBase;
|
||||
|
||||
@@ -117,8 +117,8 @@ export class PackagesService {
|
||||
remainingSeats: remaining,
|
||||
outboundSchedule: {
|
||||
scheduleId: pkg.outboundScheduleId,
|
||||
originStationId: pkg.originStationId,
|
||||
destinationStationId: pkg.destinationStationId,
|
||||
originStationId: pkg.outboundSchedule.originStationId,
|
||||
destinationStationId: pkg.outboundSchedule.destinationStationId,
|
||||
departureAt: pkg.outboundSchedule.departureAt,
|
||||
arrivalAt: pkg.outboundSchedule.arrivalAt,
|
||||
originStation: pkg.outboundSchedule.originStation,
|
||||
@@ -204,7 +204,14 @@ export class PackagesService {
|
||||
where: { id },
|
||||
include: {
|
||||
priceTiers: true,
|
||||
outboundSchedule: { include: { originStation: true, destinationStation: true, train: true } },
|
||||
outboundSchedule: {
|
||||
include: {
|
||||
originStation: true,
|
||||
destinationStation: true,
|
||||
train: true,
|
||||
stopTimes: { include: { station: true }, orderBy: { sequence: 'asc' } },
|
||||
},
|
||||
},
|
||||
returnSchedule: { include: { originStation: true, destinationStation: true, train: true } },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -50,8 +50,8 @@ export class CreateScheduleDto {
|
||||
{ sequence: 6, plannedArrivalAt: '2026-06-15T20:00:00Z' },
|
||||
],
|
||||
})
|
||||
@IsArray() @ValidateNested({ each: true }) @Type(() => PlannedStopTimeDto)
|
||||
plannedTimes: PlannedStopTimeDto[];
|
||||
@IsOptional() @IsArray() @ValidateNested({ each: true }) @Type(() => PlannedStopTimeDto)
|
||||
plannedTimes?: PlannedStopTimeDto[];
|
||||
}
|
||||
|
||||
export class UpdateScheduleDto {
|
||||
|
||||
@@ -153,7 +153,7 @@ export class SchedulesService {
|
||||
});
|
||||
}
|
||||
|
||||
const providedSeqs = new Set(plannedTimes.map(t => t.sequence));
|
||||
const providedSeqs = new Set((plannedTimes ?? []).map(t => t.sequence));
|
||||
const missingSeqs = route.stops.map(s => s.sequence).filter(seq => !providedSeqs.has(seq));
|
||||
if (missingSeqs.length > 0) {
|
||||
throw new BadRequestException(`Missing planned times for stop sequences: ${missingSeqs.join(', ')}`);
|
||||
|
||||
Reference in New Issue
Block a user