move route compute to create service as entity creation is not async

This commit is contained in:
sbriat
2023-08-22 16:14:36 +02:00
parent 4762c844e1
commit ac8e459e90
27 changed files with 403 additions and 94 deletions

View File

@@ -0,0 +1,6 @@
import { GetRouteRequestDto } from '@modules/geography/interface/controllers/dtos/get-route.request.dto';
import { RouteResponseDto } from '@modules/geography/interface/dtos/route.response.dto';
export interface GetBasicRouteControllerPort {
get(data: GetRouteRequestDto): Promise<RouteResponseDto>;
}

View File

@@ -9,6 +9,5 @@ export type Route = {
fwdAzimuth: number;
backAzimuth: number;
distanceAzimuth: number;
points: Coordinates[];
spacetimePoints: SpacetimePoint[];
points: Coordinates[] | SpacetimePoint[];
};

View File

@@ -60,9 +60,7 @@ export class RouteEntity extends AggregateRoot<RouteProps> {
? driverRoute.distanceAzimuth
: passengerRoute.distanceAzimuth,
waypoints: create.waypoints,
spacetimePoints: driverRoute
? driverRoute.spacetimePoints
: passengerRoute.spacetimePoints,
points: driverRoute ? driverRoute.points : passengerRoute.points,
};
return new RouteEntity({
id: v4(),

View File

@@ -1,5 +1,6 @@
import { GeorouterPort } from '../application/ports/georouter.port';
import { GeorouterSettings } from '../application/types/georouter-settings.type';
import { CoordinatesProps } from './value-objects/coordinates.value-object';
import { SpacetimePointProps } from './value-objects/spacetime-point.value-object';
import { WaypointProps } from './value-objects/waypoint.value-object';
@@ -13,7 +14,7 @@ export interface RouteProps {
backAzimuth: number;
distanceAzimuth: number;
waypoints: WaypointProps[];
spacetimePoints: SpacetimePointProps[];
points: SpacetimePointProps[] | CoordinatesProps[];
}
// Properties that are needed for a Route creation
@@ -31,8 +32,7 @@ export type Direction = {
fwdAzimuth: number;
backAzimuth: number;
distanceAzimuth: number;
points: Point[];
spacetimePoints: SpacetimePoint[];
points: SpacetimePoint[] | Point[];
};
export type Path = {

View File

@@ -0,0 +1,31 @@
import {
ArgumentOutOfRangeException,
ValueObject,
} from '@mobicoop/ddd-library';
/** Note:
* Value Objects with multiple properties can contain
* other Value Objects inside if needed.
* */
export interface CoordinatesProps {
lon: number;
lat: number;
}
export class Coordinates extends ValueObject<CoordinatesProps> {
get lon(): number {
return this.props.lon;
}
get lat(): number {
return this.props.lat;
}
protected validate(props: CoordinatesProps): void {
if (props.lon > 180 || props.lon < -180)
throw new ArgumentOutOfRangeException('lon must be between -180 and 180');
if (props.lat > 90 || props.lat < -90)
throw new ArgumentOutOfRangeException('lat must be between -90 and 90');
}
}