mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 14:02:39 +00:00
move route compute to create service as entity creation is not async
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
@@ -9,6 +9,5 @@ export type Route = {
|
||||
fwdAzimuth: number;
|
||||
backAzimuth: number;
|
||||
distanceAzimuth: number;
|
||||
points: Coordinates[];
|
||||
spacetimePoints: SpacetimePoint[];
|
||||
points: Coordinates[] | SpacetimePoint[];
|
||||
};
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user