simpler route provider in ad module

This commit is contained in:
sbriat
2023-09-08 16:19:25 +02:00
parent 6b4ac1792c
commit 59a2644bb4
25 changed files with 436 additions and 568 deletions

View File

@@ -27,7 +27,7 @@ export type Route = {
backAzimuth: number;
distanceAzimuth: number;
points: Point[];
steps: Step[];
steps?: Step[];
};
export type Point = {

View File

@@ -1,10 +1,11 @@
import { Point, Step } from '@modules/geography/core/domain/route.types';
export class RouteResponseDto {
distance?: number;
duration?: number;
distance: number;
duration: number;
fwdAzimuth: number;
backAzimuth: number;
distanceAzimuth: number;
points: Step[] | Point[];
points: Point[];
steps?: Step[];
}

View File

@@ -16,12 +16,8 @@ export class RouteMapper
{
toResponse = (entity: RouteEntity): RouteResponseDto => {
const response = new RouteResponseDto();
response.distance = entity.getProps().distance
? Math.round(entity.getProps().distance as number)
: undefined;
response.duration = entity.getProps().duration
? Math.round(entity.getProps().duration as number)
: undefined;
response.distance = Math.round(entity.getProps().distance);
response.duration = Math.round(entity.getProps().duration);
response.fwdAzimuth = Math.round(entity.getProps().fwdAzimuth);
response.backAzimuth = Math.round(entity.getProps().backAzimuth);
response.distanceAzimuth = Math.round(entity.getProps().distanceAzimuth);

View File

@@ -4,7 +4,7 @@ import {
GeorouterUnavailableException,
RouteNotFoundException,
} from '@modules/geography/core/domain/route.errors';
import { Route } from '@modules/geography/core/domain/route.types';
import { Route, Step } from '@modules/geography/core/domain/route.types';
import {
GEODESIC,
PARAMS_PROVIDER,
@@ -411,8 +411,8 @@ describe('Graphhopper Georouter', () => {
},
);
expect(route.steps).toHaveLength(2);
expect(route.steps[1].duration).toBe(1800);
expect(route.steps[1].distance).toBeUndefined();
expect((route.steps as Step[])[1].duration).toBe(1800);
expect((route.steps as Step[])[1].distance).toBeUndefined();
});
it('should create one route with points and missed waypoints extrapolations', async () => {
@@ -468,8 +468,8 @@ describe('Graphhopper Georouter', () => {
points: true,
},
);
expect(route.steps.length).toBe(3);
expect(route.steps[1].duration).toBe(990);
expect(route.steps[1].distance).toBe(25000);
expect(route.steps).toHaveLength(3);
expect((route.steps as Step[])[1].duration).toBe(990);
expect((route.steps as Step[])[1].distance).toBe(25000);
});
});