diff --git a/src/modules/ad/ad.mapper.ts b/src/modules/ad/ad.mapper.ts index 0f38427..18690b9 100644 --- a/src/modules/ad/ad.mapper.ts +++ b/src/modules/ad/ad.mapper.ts @@ -112,7 +112,12 @@ export class AdMapper driverDistance: record.driverDistance, passengerDuration: record.passengerDuration, passengerDistance: record.passengerDistance, - waypoints: [], + waypoints: this.directionEncoder + .decode(record.waypoints) + .map((coordinates, index) => ({ + position: index, + ...coordinates, + })), fwdAzimuth: record.fwdAzimuth, backAzimuth: record.backAzimuth, }, diff --git a/src/modules/ad/tests/unit/ad.mapper.spec.ts b/src/modules/ad/tests/unit/ad.mapper.spec.ts index a854e3d..646e7aa 100644 --- a/src/modules/ad/tests/unit/ad.mapper.spec.ts +++ b/src/modules/ad/tests/unit/ad.mapper.spec.ts @@ -92,6 +92,16 @@ const mockDirectionEncoder: DirectionEncoderPort = { () => "'LINESTRING(6.1765102 48.689445,4.984578 48.725687,2.3522 48.8566)'", ), + decode: jest.fn().mockImplementation(() => [ + { + lon: 6.1765102, + lat: 48.689445, + }, + { + lon: 2.3522, + lat: 48.8566, + }, + ]), }; const mockRouteProvider: RouteProviderPort = { @@ -161,6 +171,7 @@ describe('Ad Mapper', () => { const mapped: AdEntity = adMapper.toDomain(adReadModel); expect(mapped.getProps().schedule.length).toBe(1); expect(mapped.getProps().schedule[0].time).toBe('07:05'); + expect(mapped.getProps().waypoints.length).toBe(2); }); it('should map domain entity to response', async () => { diff --git a/src/modules/ad/tests/unit/infrastructure/ad.repository.spec.ts b/src/modules/ad/tests/unit/infrastructure/ad.repository.spec.ts index 1da3757..2dfe7e4 100644 --- a/src/modules/ad/tests/unit/infrastructure/ad.repository.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/ad.repository.spec.ts @@ -16,6 +16,7 @@ const mockMessagePublisher = { const mockDirectionEncoder: DirectionEncoderPort = { encode: jest.fn(), + decode: jest.fn(), }; const mockRouteProvider: RouteProviderPort = { diff --git a/src/modules/geography/core/application/ports/direction-encoder.port.ts b/src/modules/geography/core/application/ports/direction-encoder.port.ts index 333f8ba..3251915 100644 --- a/src/modules/geography/core/application/ports/direction-encoder.port.ts +++ b/src/modules/geography/core/application/ports/direction-encoder.port.ts @@ -2,4 +2,5 @@ import { Coordinates } from '../types/coordinates.type'; export interface DirectionEncoderPort { encode(coordinates: Coordinates[]): string; + decode(direction: string): Coordinates[]; } diff --git a/src/modules/geography/infrastructure/postgres-direction-encoder.ts b/src/modules/geography/infrastructure/postgres-direction-encoder.ts index 5d4aa3b..b4c8001 100644 --- a/src/modules/geography/infrastructure/postgres-direction-encoder.ts +++ b/src/modules/geography/infrastructure/postgres-direction-encoder.ts @@ -10,4 +10,14 @@ export class PostgresDirectionEncoder implements DirectionEncoderPort { coordinates.map((point) => [point.lon, point.lat].join(' ')).join(), ")'", ].join(''); + decode = (direction: string): Coordinates[] => + direction + .split('(')[1] + .split(')')[0] + .split(',') + .map((coordinates) => coordinates.split(' ')) + .map((point) => ({ + lon: parseFloat(point[0]), + lat: parseFloat(point[1]), + })); }