Excess baggage payment link changes

This commit is contained in:
Stephanos A
2026-08-05 10:37:49 +03:00
parent fa7fb6b7ea
commit d1a15a82e3
6 changed files with 275 additions and 19 deletions

View File

@@ -2,7 +2,10 @@ import { IsString, IsInt, IsOptional, IsPositive } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class LogExcessBaggageDto {
@ApiProperty({ example: 'booking-uuid' }) @IsString() bookingId: string;
@ApiPropertyOptional({ example: 'booking-uuid', description: 'Booking UUID for the passenger booking' })
@IsOptional() @IsString() bookingId?: string;
@ApiPropertyOptional({ example: 'JS6MJ9', description: 'Booking reference for the passenger booking' })
@IsOptional() @IsString() bookingReference?: string;
@ApiPropertyOptional({ example: 'agent-uuid', description: 'Injected from IAM token; optional override' })
@IsOptional() @IsString() agentId?: string;
@ApiProperty({ example: 7, description: 'Excess weight in kg above the free allowance' })

View File

@@ -39,12 +39,25 @@ export class ExcessBaggageService {
) {}
async logCharge(dto: LogExcessBaggageDto) {
const booking = await this.prisma.booking.findUnique({
where: { id: dto.bookingId },
include: {
passenger: { include: { user: true } },
},
});
const bookingRef = dto.bookingReference?.trim();
const bookingId = dto.bookingId?.trim();
const booking = bookingRef
? await this.prisma.booking.findFirst({
where: { bookingRef: { equals: bookingRef, mode: 'insensitive' } },
include: {
passenger: { include: { user: true } },
},
})
: bookingId
? await this.prisma.booking.findUnique({
where: { id: bookingId },
include: {
passenger: { include: { user: true } },
},
})
: null;
if (!booking) throw new NotFoundException('Booking not found');
if (!['CONFIRMED', 'BOARDED'].includes(booking.status)) {
throw new BadRequestException('Booking must be CONFIRMED or BOARDED to log excess baggage');
@@ -64,7 +77,7 @@ export class ExcessBaggageService {
const charge = await this.prisma.excessBaggageCharge.create({
data: {
bookingId: dto.bookingId,
bookingId: booking.id,
agentId: dto.agentId ?? '',
excessWeightKg: dto.excessWeightKg,
feePerKgMinor,
@@ -81,7 +94,7 @@ export class ExcessBaggageService {
await this.sendPaymentLink(charge, booking, contactPhone, contactEmail);
}
await this.auditService.log({ action: 'CREATE', entityType: 'ExcessBaggageCharge', entityId: charge.id, newData: { bookingId: dto.bookingId, excessWeightKg: dto.excessWeightKg, totalMinor, status } });
await this.auditService.log({ action: 'CREATE', entityType: 'ExcessBaggageCharge', entityId: charge.id, newData: { bookingId: booking.id, excessWeightKg: dto.excessWeightKg, totalMinor, status } });
return charge;
}