mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-01 22:53:26 +00:00
Updated seat class and coach mangement
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { IsString, IsDateString, IsInt, IsOptional, IsEnum } from 'class-validator';
|
||||
import { IsString, IsDateString, IsInt, IsOptional } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { ServiceClass } from '@prisma/client';
|
||||
|
||||
export class CreateTripDto {
|
||||
@ApiProperty() @IsString() serviceId: string;
|
||||
@@ -14,7 +13,7 @@ export class CreateTripDto {
|
||||
export class CreateFareRuleDto {
|
||||
@ApiPropertyOptional() @IsOptional() @IsString() tripId?: string;
|
||||
@ApiPropertyOptional() @IsOptional() @IsString() route?: string;
|
||||
@ApiProperty({ enum: ServiceClass }) @IsEnum(ServiceClass) serviceClass: ServiceClass;
|
||||
@ApiProperty({ example: 'seat-class-uuid' }) @IsString() seatClassId: string;
|
||||
@ApiProperty({ example: 45000 }) @IsInt() baseFareMinor: number;
|
||||
@ApiProperty({ example: '2026-01-01T00:00:00Z' }) @IsDateString() validFrom: string;
|
||||
@ApiPropertyOptional() @IsOptional() @IsDateString() validUntil?: string;
|
||||
|
||||
@@ -26,14 +26,14 @@ export class SchedulesService {
|
||||
return this.prisma.fareRule.create({ data: { ...dto, validFrom: new Date(dto.validFrom), validUntil: dto.validUntil ? new Date(dto.validUntil) : null } });
|
||||
}
|
||||
|
||||
async getFare(tripId: string, serviceClass: string) {
|
||||
async getFare(tripId: string, seatClassId: string) {
|
||||
const trip = await this.prisma.trip.findUnique({ where: { id: tripId }, include: { originStation: true, destinationStation: true } });
|
||||
if (!trip) throw new NotFoundException('Trip not found');
|
||||
const route = `${trip.originStation.code}-${trip.destinationStation.code}`;
|
||||
const rule = await this.prisma.fareRule.findFirst({
|
||||
where: { serviceClass: serviceClass as any, validFrom: { lte: new Date() }, OR: [{ tripId }, { route }, { tripId: null, route: null }], AND: [{ OR: [{ validUntil: null }, { validUntil: { gte: new Date() } }] }] },
|
||||
where: { seatClassId, validFrom: { lte: new Date() }, OR: [{ tripId }, { route }, { tripId: null, route: null }], AND: [{ OR: [{ validUntil: null }, { validUntil: { gte: new Date() } }] }] },
|
||||
orderBy: { validFrom: 'desc' },
|
||||
});
|
||||
return rule ?? { baseFareMinor: 45000, currency: 'ETB', serviceClass };
|
||||
return rule ?? { baseFareMinor: 45000, currency: 'ETB', seatClassId };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user