mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 08:22:41 +00:00
functional ad insert
This commit is contained in:
@@ -13,6 +13,9 @@ import { RouteMapper } from './route.mapper';
|
||||
import { Geodesic } from './infrastructure/geodesic';
|
||||
import { GraphhopperGeorouter } from './infrastructure/graphhopper-georouter';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { GetRouteQueryHandler } from './core/application/queries/get-route/get-route.query-handler';
|
||||
|
||||
const queryHandlers: Provider[] = [GetRouteQueryHandler];
|
||||
|
||||
const mappers: Provider[] = [RouteMapper];
|
||||
|
||||
@@ -38,7 +41,7 @@ const adapters: Provider[] = [
|
||||
|
||||
@Module({
|
||||
imports: [CqrsModule, HttpModule],
|
||||
providers: [...mappers, ...adapters],
|
||||
providers: [...queryHandlers, ...mappers, ...adapters],
|
||||
exports: [RouteMapper, DIRECTION_ENCODER, GetBasicRouteController],
|
||||
})
|
||||
export class GeographyModule {}
|
||||
|
||||
@@ -26,13 +26,17 @@ export class RouteMapper
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
toResponse = (entity: RouteEntity): RouteResponseDto => {
|
||||
const response = new RouteResponseDto();
|
||||
response.driverDistance = entity.getProps().driverDistance;
|
||||
response.driverDuration = entity.getProps().driverDuration;
|
||||
response.passengerDistance = entity.getProps().passengerDistance;
|
||||
response.passengerDuration = entity.getProps().passengerDuration;
|
||||
response.fwdAzimuth = entity.getProps().fwdAzimuth;
|
||||
response.backAzimuth = entity.getProps().backAzimuth;
|
||||
response.distanceAzimuth = entity.getProps().distanceAzimuth;
|
||||
response.driverDistance = Math.round(entity.getProps().driverDistance);
|
||||
response.driverDuration = Math.round(entity.getProps().driverDuration);
|
||||
response.passengerDistance = Math.round(
|
||||
entity.getProps().passengerDistance,
|
||||
);
|
||||
response.passengerDuration = Math.round(
|
||||
entity.getProps().passengerDuration,
|
||||
);
|
||||
response.fwdAzimuth = Math.round(entity.getProps().fwdAzimuth);
|
||||
response.backAzimuth = Math.round(entity.getProps().backAzimuth);
|
||||
response.distanceAzimuth = Math.round(entity.getProps().distanceAzimuth);
|
||||
response.points = entity.getProps().points;
|
||||
return response;
|
||||
};
|
||||
|
||||
@@ -4,25 +4,25 @@ import { Coordinates } from '@modules/geography/core/domain/value-objects/coordi
|
||||
describe('Waypoint value object', () => {
|
||||
it('should create a waypoint value object', () => {
|
||||
const coordinatesVO = new Coordinates({
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
expect(coordinatesVO.lon).toBe(48.689445);
|
||||
expect(coordinatesVO.lat).toBe(6.17651);
|
||||
expect(coordinatesVO.lat).toBe(48.689445);
|
||||
expect(coordinatesVO.lon).toBe(6.17651);
|
||||
});
|
||||
it('should throw an exception if longitude is invalid', () => {
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: 348.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 186.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: -348.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: -186.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
@@ -31,16 +31,16 @@ describe('Waypoint value object', () => {
|
||||
it('should throw an exception if latitude is invalid', () => {
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: 48.689445,
|
||||
lat: 96.17651,
|
||||
lat: 148.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
}
|
||||
try {
|
||||
new Coordinates({
|
||||
lon: 48.689445,
|
||||
lat: -96.17651,
|
||||
lat: -148.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
|
||||
@@ -8,13 +8,13 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const originWaypoint: Waypoint = {
|
||||
position: 0,
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
};
|
||||
const destinationWaypoint: Waypoint = {
|
||||
position: 1,
|
||||
lon: 48.8566,
|
||||
lat: 2.3522,
|
||||
lat: 48.8566,
|
||||
lon: 2.3522,
|
||||
};
|
||||
|
||||
const mockGeorouter: GeorouterPort = {
|
||||
|
||||
@@ -9,12 +9,12 @@ import {
|
||||
} from '@modules/geography/core/domain/route.types';
|
||||
|
||||
const originCoordinates: Coordinates = {
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
};
|
||||
const destinationCoordinates: Coordinates = {
|
||||
lon: 48.8566,
|
||||
lat: 2.3522,
|
||||
lat: 48.8566,
|
||||
lon: 2.3522,
|
||||
};
|
||||
const additionalCoordinates: Coordinates = {
|
||||
lon: 48.7566,
|
||||
|
||||
@@ -7,21 +7,21 @@ import { SpacetimePoint } from '@modules/geography/core/domain/value-objects/spa
|
||||
describe('Timepoint value object', () => {
|
||||
it('should create a timepoint value object', () => {
|
||||
const timepointVO = new SpacetimePoint({
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
expect(timepointVO.duration).toBe(150);
|
||||
expect(timepointVO.distance).toBe(12000);
|
||||
expect(timepointVO.lon).toBe(48.689445);
|
||||
expect(timepointVO.lat).toBe(6.17651);
|
||||
expect(timepointVO.lat).toBe(48.689445);
|
||||
expect(timepointVO.lon).toBe(6.17651);
|
||||
});
|
||||
it('should throw an exception if longitude is invalid', () => {
|
||||
try {
|
||||
new SpacetimePoint({
|
||||
lon: 348.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 186.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
@@ -30,8 +30,8 @@ describe('Timepoint value object', () => {
|
||||
}
|
||||
try {
|
||||
new SpacetimePoint({
|
||||
lon: -348.689445,
|
||||
lat: 6.17651,
|
||||
lon: 48.689445,
|
||||
lat: -186.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
@@ -42,8 +42,8 @@ describe('Timepoint value object', () => {
|
||||
it('should throw an exception if latitude is invalid', () => {
|
||||
try {
|
||||
new SpacetimePoint({
|
||||
lon: 48.689445,
|
||||
lat: 96.17651,
|
||||
lat: 248.689445,
|
||||
lon: 6.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
@@ -52,8 +52,8 @@ describe('Timepoint value object', () => {
|
||||
}
|
||||
try {
|
||||
new SpacetimePoint({
|
||||
lon: 48.689445,
|
||||
lat: -96.17651,
|
||||
lon: -148.689445,
|
||||
lat: 6.17651,
|
||||
duration: 150,
|
||||
distance: 12000,
|
||||
});
|
||||
@@ -64,8 +64,8 @@ describe('Timepoint value object', () => {
|
||||
it('should throw an exception if distance is invalid', () => {
|
||||
try {
|
||||
new SpacetimePoint({
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
duration: 150,
|
||||
distance: -12000,
|
||||
});
|
||||
@@ -76,8 +76,8 @@ describe('Timepoint value object', () => {
|
||||
it('should throw an exception if duration is invalid', () => {
|
||||
try {
|
||||
new SpacetimePoint({
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
duration: -150,
|
||||
distance: 12000,
|
||||
});
|
||||
|
||||
@@ -8,19 +8,19 @@ describe('Waypoint value object', () => {
|
||||
it('should create a waypoint value object', () => {
|
||||
const waypointVO = new Waypoint({
|
||||
position: 0,
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
expect(waypointVO.position).toBe(0);
|
||||
expect(waypointVO.lon).toBe(48.689445);
|
||||
expect(waypointVO.lat).toBe(6.17651);
|
||||
expect(waypointVO.lat).toBe(48.689445);
|
||||
expect(waypointVO.lon).toBe(6.17651);
|
||||
});
|
||||
it('should throw an exception if position is invalid', () => {
|
||||
try {
|
||||
new Waypoint({
|
||||
position: -1,
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentInvalidException);
|
||||
@@ -30,8 +30,8 @@ describe('Waypoint value object', () => {
|
||||
try {
|
||||
new Waypoint({
|
||||
position: 0,
|
||||
lon: 348.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 186.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
@@ -39,8 +39,8 @@ describe('Waypoint value object', () => {
|
||||
try {
|
||||
new Waypoint({
|
||||
position: 0,
|
||||
lon: -348.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: -186.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
@@ -50,8 +50,8 @@ describe('Waypoint value object', () => {
|
||||
try {
|
||||
new Waypoint({
|
||||
position: 0,
|
||||
lon: 48.689445,
|
||||
lat: 96.17651,
|
||||
lat: 148.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
@@ -59,8 +59,8 @@ describe('Waypoint value object', () => {
|
||||
try {
|
||||
new Waypoint({
|
||||
position: 0,
|
||||
lon: 48.689445,
|
||||
lat: -96.17651,
|
||||
lat: -148.689445,
|
||||
lon: 6.17651,
|
||||
});
|
||||
} catch (e: any) {
|
||||
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
|
||||
|
||||
@@ -52,13 +52,13 @@ describe('Get Basic Route Controller', () => {
|
||||
waypoints: [
|
||||
{
|
||||
position: 0,
|
||||
lon: 48.689445,
|
||||
lat: 6.17651,
|
||||
lat: 48.689445,
|
||||
lon: 6.17651,
|
||||
},
|
||||
{
|
||||
position: 1,
|
||||
lon: 48.8566,
|
||||
lat: 2.3522,
|
||||
lat: 48.8566,
|
||||
lon: 2.3522,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user