mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 14:02:39 +00:00
route tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
export type GeorouterSettings = {
|
||||
withPoints: boolean;
|
||||
withTime: boolean;
|
||||
withDistance: boolean;
|
||||
points: boolean;
|
||||
detailedDuration: boolean;
|
||||
detailedDistance: boolean;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PathType } from '../../domain/route.types';
|
||||
import { Point } from './point.type';
|
||||
import { Coordinates } from './coordinates.type';
|
||||
|
||||
export type Path = {
|
||||
type: PathType;
|
||||
points: Point[];
|
||||
points: Coordinates[];
|
||||
};
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import { PointContext } from '../../domain/route.types';
|
||||
import { Coordinates } from './coordinates.type';
|
||||
|
||||
export type Point = Coordinates & {
|
||||
context?: PointContext;
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PathType } from '../../domain/route.types';
|
||||
import { Point } from './point.type';
|
||||
import { Coordinates } from './coordinates.type';
|
||||
import { SpacetimePoint } from './spacetime-point.type';
|
||||
|
||||
export type Route = {
|
||||
@@ -9,6 +9,6 @@ export type Route = {
|
||||
fwdAzimuth: number;
|
||||
backAzimuth: number;
|
||||
distanceAzimuth: number;
|
||||
points: Point[];
|
||||
points: Coordinates[];
|
||||
spacetimePoints: SpacetimePoint[];
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Point } from './point.type';
|
||||
import { Coordinates } from './coordinates.type';
|
||||
|
||||
export type SpacetimePoint = Point & {
|
||||
export type SpacetimePoint = Coordinates & {
|
||||
duration: number;
|
||||
distance: number;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Point } from './point.type';
|
||||
import { Coordinates } from './coordinates.type';
|
||||
|
||||
export type Waypoint = Point & {
|
||||
export type Waypoint = Coordinates & {
|
||||
position: number;
|
||||
};
|
||||
|
||||
@@ -10,15 +10,23 @@ import {
|
||||
import { WaypointProps } from './value-objects/waypoint.value-object';
|
||||
import { Route } from '../application/types/route.type';
|
||||
import { v4 } from 'uuid';
|
||||
import { RouteNotFoundException } from './route.errors';
|
||||
|
||||
export class RouteEntity extends AggregateRoot<RouteProps> {
|
||||
protected readonly _id: AggregateID;
|
||||
|
||||
static create = async (create: CreateRouteProps): Promise<RouteEntity> => {
|
||||
const directions: Direction[] = await create.georouter.routes(
|
||||
this.getPaths(create.roles, create.waypoints),
|
||||
create.georouterSettings,
|
||||
);
|
||||
let directions: Direction[];
|
||||
try {
|
||||
directions = await create.georouter.routes(
|
||||
this.getPaths(create.roles, create.waypoints),
|
||||
create.georouterSettings,
|
||||
);
|
||||
if (!directions || directions.length == 0)
|
||||
throw new RouteNotFoundException();
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
let driverRoute: Route;
|
||||
let passengerRoute: Route;
|
||||
if (directions.some((route: Route) => route.type == PathType.GENERIC)) {
|
||||
|
||||
11
src/modules/geography/core/domain/route.errors.ts
Normal file
11
src/modules/geography/core/domain/route.errors.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ExceptionBase } from '@mobicoop/ddd-library';
|
||||
|
||||
export class RouteNotFoundException extends ExceptionBase {
|
||||
static readonly message = 'Route not found';
|
||||
|
||||
public readonly code = 'ROUTE.NOT_FOUND';
|
||||
|
||||
constructor(cause?: Error, metadata?: unknown) {
|
||||
super(RouteNotFoundException.message, cause, metadata);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user