mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 05:25:41 +00:00
Routes management issue fix
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import { IsString, IsInt, IsOptional, IsArray, ValidateNested, IsBoolean, IsDateString, Min } from 'class-validator';
|
import { IsString, IsInt, IsNumber, IsOptional, IsArray, ValidateNested, IsBoolean, IsDateString, Min } from 'class-validator';
|
||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
|
|
||||||
export class RouteStopInputDto {
|
export class RouteStopInputDto {
|
||||||
@ApiProperty({ example: 'station-uuid', description: 'Station UUID' }) @IsString() stationId: string;
|
@ApiProperty({ example: 'station-uuid', description: 'Station UUID' }) @IsString() stationId: string;
|
||||||
@ApiProperty({ example: 1, description: 'Stop order (1 = origin, ascending)' }) @IsInt() @Min(1) sequence: number;
|
@ApiProperty({ example: 1, description: 'Stop order (1 = origin, ascending)' }) @IsInt() @Min(1) sequence: number;
|
||||||
@ApiPropertyOptional({ example: 120, description: 'Distance in km from previous stop' }) @IsOptional() @IsInt() distanceKm?: number;
|
@ApiPropertyOptional({ example: 120.5, description: 'Distance in km from previous stop' }) @IsOptional() @IsNumber() distanceKm?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateRouteDto {
|
export class CreateRouteDto {
|
||||||
@@ -34,7 +34,7 @@ export class CreateRouteDto {
|
|||||||
export class AddRouteStopDto {
|
export class AddRouteStopDto {
|
||||||
@ApiProperty({ example: 'station-uuid' }) @IsString() stationId: string;
|
@ApiProperty({ example: 'station-uuid' }) @IsString() stationId: string;
|
||||||
@ApiProperty({ example: 3 }) @IsInt() @Min(1) sequence: number;
|
@ApiProperty({ example: 3 }) @IsInt() @Min(1) sequence: number;
|
||||||
@ApiPropertyOptional({ example: 75 }) @IsOptional() @IsInt() distanceKm?: number;
|
@ApiPropertyOptional({ example: 75.5 }) @IsOptional() @IsNumber() distanceKm?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateRouteDto {
|
export class UpdateRouteDto {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class RoutesService {
|
|||||||
create: dto.stops.map(s => ({
|
create: dto.stops.map(s => ({
|
||||||
stationId: s.stationId,
|
stationId: s.stationId,
|
||||||
sequence: s.sequence,
|
sequence: s.sequence,
|
||||||
distanceKm: s.distanceKm,
|
distanceKm: s.distanceKm != null ? parseFloat(String(s.distanceKm)) : null,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -135,7 +135,12 @@ export class RoutesService {
|
|||||||
if (existing) throw new ConflictException(`Sequence ${dto.sequence} already exists on this route`);
|
if (existing) throw new ConflictException(`Sequence ${dto.sequence} already exists on this route`);
|
||||||
|
|
||||||
return this.prisma.routeStop.create({
|
return this.prisma.routeStop.create({
|
||||||
data: { routeId, stationId: dto.stationId, sequence: dto.sequence, distanceKm: dto.distanceKm },
|
data: {
|
||||||
|
routeId,
|
||||||
|
stationId: dto.stationId,
|
||||||
|
sequence: dto.sequence,
|
||||||
|
distanceKm: dto.distanceKm != null ? parseFloat(String(dto.distanceKm)) : null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user