mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 17:38:12 +00:00
Refactor business logic for train,schedule,coach,seat and search modules
This commit is contained in:
@@ -13,7 +13,7 @@ export class AgentPassengerDto {
|
||||
|
||||
export class CreateAgentBookingDto {
|
||||
@ApiProperty() @IsString() agentId: string;
|
||||
@ApiProperty() @IsString() tripId: string;
|
||||
@ApiProperty({ example: 'schedule-uuid' }) @IsString() scheduleId: string;
|
||||
@ApiProperty({ type: [AgentPassengerDto] }) @IsArray() @ValidateNested({ each: true }) @Type(() => AgentPassengerDto) passengers: AgentPassengerDto[];
|
||||
@ApiProperty() @IsString() paymentMethod: string;
|
||||
@ApiPropertyOptional() @IsOptional() @IsInt() cashReceived?: number;
|
||||
|
||||
@@ -17,8 +17,8 @@ export class AgentsService {
|
||||
if (!agent || !agent.active) throw new NotFoundException('Agent not found or inactive');
|
||||
if (!agent.user.passenger) throw new BadRequestException('Agent must have passenger account');
|
||||
|
||||
const trip = await this.prisma.trip.findUnique({ where: { id: dto.tripId } });
|
||||
if (!trip) throw new NotFoundException('Trip not found');
|
||||
const schedule = await this.prisma.trainSchedule.findUnique({ where: { id: dto.scheduleId } });
|
||||
if (!schedule) throw new NotFoundException('Schedule not found');
|
||||
|
||||
const seatIds = dto.passengers.map(p => p.seatId);
|
||||
const seats = await this.prisma.seat.findMany({ where: { id: { in: seatIds } } });
|
||||
@@ -31,7 +31,7 @@ export class AgentsService {
|
||||
data: {
|
||||
bookingRef: generateRef(),
|
||||
passengerId: agent.user.passenger.id,
|
||||
tripId: dto.tripId,
|
||||
scheduleId: dto.scheduleId,
|
||||
status: dto.paymentMethod === 'CASH' ? 'CONFIRMED' : 'PENDING_PAYMENT',
|
||||
totalMinor,
|
||||
seats: {
|
||||
|
||||
Reference in New Issue
Block a user