simplify ad
This commit is contained in:
parent
bff199557a
commit
1dd44b1425
|
@ -12,7 +12,7 @@ import { ScheduleItemProps } from './core/domain/value-objects/schedule-item.val
|
||||||
import { DirectionEncoderPort } from '@modules/geography/core/application/ports/direction-encoder.port';
|
import { DirectionEncoderPort } from '@modules/geography/core/application/ports/direction-encoder.port';
|
||||||
import { AD_DIRECTION_ENCODER, AD_ROUTE_PROVIDER } from './ad.di-tokens';
|
import { AD_DIRECTION_ENCODER, AD_ROUTE_PROVIDER } from './ad.di-tokens';
|
||||||
import { RouteProviderPort } from './core/application/ports/route-provider.port';
|
import { RouteProviderPort } from './core/application/ports/route-provider.port';
|
||||||
import { RouteResponseDto } from '@modules/geography/interface/dtos/route.response.dto';
|
import { Route } from './core/application/types/route.type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapper constructs objects that are used in different layers:
|
* Mapper constructs objects that are used in different layers:
|
||||||
|
@ -38,15 +38,11 @@ export class AdMapper
|
||||||
const roles: Role[] = [];
|
const roles: Role[] = [];
|
||||||
if (copy.driver) roles.push(Role.DRIVER);
|
if (copy.driver) roles.push(Role.DRIVER);
|
||||||
if (copy.passenger) roles.push(Role.PASSENGER);
|
if (copy.passenger) roles.push(Role.PASSENGER);
|
||||||
const route: RouteResponseDto = this.routeProvider.get(
|
const route: Route = this.routeProvider.get(roles, copy.waypoints, {
|
||||||
roles,
|
points: true,
|
||||||
copy.waypoints,
|
detailedDistance: false,
|
||||||
{
|
detailedDuration: false,
|
||||||
withDistance: true,
|
});
|
||||||
withPoints: true,
|
|
||||||
withTime: false,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const record: AdWriteModel = {
|
const record: AdWriteModel = {
|
||||||
uuid: copy.id,
|
uuid: copy.id,
|
||||||
driver: copy.driver,
|
driver: copy.driver,
|
||||||
|
@ -78,7 +74,7 @@ export class AdMapper
|
||||||
passengerDuration: route.passengerDuration,
|
passengerDuration: route.passengerDuration,
|
||||||
passengerDistance: route.passengerDistance,
|
passengerDistance: route.passengerDistance,
|
||||||
waypoints: this.directionEncoder.encode(copy.waypoints),
|
waypoints: this.directionEncoder.encode(copy.waypoints),
|
||||||
direction: this.directionEncoder.encode(route.spacetimePoints),
|
direction: this.directionEncoder.encode(route.points),
|
||||||
fwdAzimuth: route.fwdAzimuth,
|
fwdAzimuth: route.fwdAzimuth,
|
||||||
backAzimuth: route.backAzimuth,
|
backAzimuth: route.backAzimuth,
|
||||||
createdAt: copy.createdAt,
|
createdAt: copy.createdAt,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { GeorouterSettings } from '@modules/geography/core/application/types/georouter-settings.type';
|
import { GeorouterSettings } from '../types/georouter-settings.type';
|
||||||
import { Waypoint } from '@modules/geography/core/application/types/waypoint.type';
|
|
||||||
import { RouteResponseDto } from '@modules/geography/interface/dtos/route.response.dto';
|
|
||||||
import { Role } from '../../domain/ad.types';
|
import { Role } from '../../domain/ad.types';
|
||||||
|
import { Waypoint } from '../types/waypoint.type';
|
||||||
|
import { Route } from '../types/route.type';
|
||||||
|
|
||||||
export interface RouteProviderPort {
|
export interface RouteProviderPort {
|
||||||
get(
|
get(
|
||||||
roles: Role[],
|
roles: Role[],
|
||||||
waypoints: Waypoint[],
|
waypoints: Waypoint[],
|
||||||
georouterSettings: GeorouterSettings,
|
georouterSettings: GeorouterSettings,
|
||||||
): RouteResponseDto;
|
): Route;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
export type Coordinates = {
|
||||||
|
lon: number;
|
||||||
|
lat: number;
|
||||||
|
};
|
|
@ -0,0 +1,5 @@
|
||||||
|
export type GeorouterSettings = {
|
||||||
|
points: boolean;
|
||||||
|
detailedDuration: boolean;
|
||||||
|
detailedDistance: boolean;
|
||||||
|
};
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { Coordinates } from './coordinates.type';
|
||||||
|
|
||||||
|
export type Route = {
|
||||||
|
driverDistance?: number;
|
||||||
|
driverDuration?: number;
|
||||||
|
passengerDistance?: number;
|
||||||
|
passengerDuration?: number;
|
||||||
|
fwdAzimuth: number;
|
||||||
|
backAzimuth: number;
|
||||||
|
points: Coordinates[];
|
||||||
|
};
|
|
@ -1,8 +1,5 @@
|
||||||
import { PointContext } from '../../domain/ad.types';
|
import { Coordinates } from './coordinates.type';
|
||||||
|
|
||||||
export type Waypoint = {
|
export type Waypoint = {
|
||||||
position: number;
|
position: number;
|
||||||
context?: PointContext;
|
} & Coordinates;
|
||||||
lon: number;
|
|
||||||
lat: number;
|
|
||||||
};
|
|
||||||
|
|
|
@ -41,14 +41,6 @@ export enum Frequency {
|
||||||
RECURRENT = 'RECURRENT',
|
RECURRENT = 'RECURRENT',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PointContext {
|
|
||||||
HOUSE_NUMBER = 'HOUSE_NUMBER',
|
|
||||||
STREET_ADDRESS = 'STREET_ADDRESS',
|
|
||||||
LOCALITY = 'LOCALITY',
|
|
||||||
VENUE = 'VENUE',
|
|
||||||
OTHER = 'OTHER',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum Role {
|
export enum Role {
|
||||||
DRIVER = 'DRIVER',
|
DRIVER = 'DRIVER',
|
||||||
PASSENGER = 'PASSENGER',
|
PASSENGER = 'PASSENGER',
|
||||||
|
|
|
@ -3,7 +3,6 @@ import {
|
||||||
ArgumentOutOfRangeException,
|
ArgumentOutOfRangeException,
|
||||||
ValueObject,
|
ValueObject,
|
||||||
} from '@mobicoop/ddd-library';
|
} from '@mobicoop/ddd-library';
|
||||||
import { PointContext } from '../ad.types';
|
|
||||||
|
|
||||||
/** Note:
|
/** Note:
|
||||||
* Value Objects with multiple properties can contain
|
* Value Objects with multiple properties can contain
|
||||||
|
@ -14,7 +13,6 @@ export interface WaypointProps {
|
||||||
position: number;
|
position: number;
|
||||||
lon: number;
|
lon: number;
|
||||||
lat: number;
|
lat: number;
|
||||||
context?: PointContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Waypoint extends ValueObject<WaypointProps> {
|
export class Waypoint extends ValueObject<WaypointProps> {
|
||||||
|
@ -30,10 +28,6 @@ export class Waypoint extends ValueObject<WaypointProps> {
|
||||||
return this.props.lat;
|
return this.props.lat;
|
||||||
}
|
}
|
||||||
|
|
||||||
get context(): PointContext {
|
|
||||||
return this.props.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected validate(props: WaypointProps): void {
|
protected validate(props: WaypointProps): void {
|
||||||
if (props.position < 0)
|
if (props.position < 0)
|
||||||
throw new ArgumentInvalidException(
|
throw new ArgumentInvalidException(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Frequency, PointContext } from '@modules/ad/core/domain/ad.types';
|
import { Frequency } from '@modules/ad/core/domain/ad.types';
|
||||||
|
|
||||||
export type Ad = {
|
export type Ad = {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -31,5 +31,4 @@ export type Waypoint = {
|
||||||
country: string;
|
country: string;
|
||||||
lon: number;
|
lon: number;
|
||||||
lat: number;
|
lat: number;
|
||||||
context?: PointContext;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -103,7 +103,20 @@ const mockRouteProvider: RouteProviderPort = {
|
||||||
fwdAzimuth: 273,
|
fwdAzimuth: 273,
|
||||||
backAzimuth: 93,
|
backAzimuth: 93,
|
||||||
distanceAzimuth: 336544,
|
distanceAzimuth: 336544,
|
||||||
spacetimePoints: [],
|
points: [
|
||||||
|
{
|
||||||
|
lon: 6.1765102,
|
||||||
|
lat: 48.689445,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lon: 4.984578,
|
||||||
|
lat: 48.725687,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lon: 2.3522,
|
||||||
|
lat: 48.8566,
|
||||||
|
},
|
||||||
|
],
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,10 @@ import {
|
||||||
ArgumentInvalidException,
|
ArgumentInvalidException,
|
||||||
ArgumentOutOfRangeException,
|
ArgumentOutOfRangeException,
|
||||||
} from '@mobicoop/ddd-library';
|
} from '@mobicoop/ddd-library';
|
||||||
import { PointContext } from '@modules/ad/core/domain/ad.types';
|
|
||||||
import { Waypoint } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
import { Waypoint } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
||||||
|
|
||||||
describe('Waypoint value object', () => {
|
describe('Waypoint value object', () => {
|
||||||
it('should create a waypoint value object without context', () => {
|
it('should create a waypoint value object', () => {
|
||||||
const waypointVO = new Waypoint({
|
const waypointVO = new Waypoint({
|
||||||
position: 0,
|
position: 0,
|
||||||
lon: 48.689445,
|
lon: 48.689445,
|
||||||
|
@ -15,19 +14,6 @@ describe('Waypoint value object', () => {
|
||||||
expect(waypointVO.position).toBe(0);
|
expect(waypointVO.position).toBe(0);
|
||||||
expect(waypointVO.lon).toBe(48.689445);
|
expect(waypointVO.lon).toBe(48.689445);
|
||||||
expect(waypointVO.lat).toBe(6.17651);
|
expect(waypointVO.lat).toBe(6.17651);
|
||||||
expect(waypointVO.context).toBeUndefined();
|
|
||||||
});
|
|
||||||
it('should create a waypoint value object with context', () => {
|
|
||||||
const waypointVO = new Waypoint({
|
|
||||||
position: 0,
|
|
||||||
lon: 48.689445,
|
|
||||||
lat: 6.17651,
|
|
||||||
context: PointContext.HOUSE_NUMBER,
|
|
||||||
});
|
|
||||||
expect(waypointVO.position).toBe(0);
|
|
||||||
expect(waypointVO.lon).toBe(48.689445);
|
|
||||||
expect(waypointVO.lat).toBe(6.17651);
|
|
||||||
expect(waypointVO.context).toBe(PointContext.HOUSE_NUMBER);
|
|
||||||
});
|
});
|
||||||
it('should throw an exception if position is invalid', () => {
|
it('should throw an exception if position is invalid', () => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue