mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2025-12-31 10:02:42 +00:00
refactor to ddh, first commit
This commit is contained in:
109
old/modules/ad/domain/entities/ad.ts
Normal file
109
old/modules/ad/domain/entities/ad.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import { AutoMap } from '@automapper/classes';
|
||||
import { Frequency } from '../types/frequency.enum';
|
||||
|
||||
export class Ad {
|
||||
@AutoMap()
|
||||
uuid: string;
|
||||
|
||||
@AutoMap()
|
||||
userUuid: string;
|
||||
|
||||
@AutoMap()
|
||||
driver: boolean;
|
||||
|
||||
@AutoMap()
|
||||
passenger: boolean;
|
||||
|
||||
@AutoMap()
|
||||
frequency: Frequency;
|
||||
|
||||
@AutoMap()
|
||||
fromDate: Date;
|
||||
|
||||
@AutoMap()
|
||||
toDate: Date;
|
||||
|
||||
@AutoMap()
|
||||
monTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
tueTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
wedTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
thuTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
friTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
satTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
sunTime: Date;
|
||||
|
||||
@AutoMap()
|
||||
monMargin: number;
|
||||
|
||||
@AutoMap()
|
||||
tueMargin: number;
|
||||
|
||||
@AutoMap()
|
||||
wedMargin: number;
|
||||
|
||||
@AutoMap()
|
||||
thuMargin: number;
|
||||
|
||||
@AutoMap()
|
||||
friMargin: number;
|
||||
|
||||
@AutoMap()
|
||||
satMargin: number;
|
||||
|
||||
@AutoMap()
|
||||
sunMargin: number;
|
||||
|
||||
@AutoMap()
|
||||
driverDuration?: number;
|
||||
|
||||
@AutoMap()
|
||||
driverDistance?: number;
|
||||
|
||||
@AutoMap()
|
||||
passengerDuration?: number;
|
||||
|
||||
@AutoMap()
|
||||
passengerDistance?: number;
|
||||
|
||||
@AutoMap()
|
||||
waypoints: string;
|
||||
|
||||
@AutoMap()
|
||||
direction: string;
|
||||
|
||||
@AutoMap()
|
||||
fwdAzimuth: number;
|
||||
|
||||
@AutoMap()
|
||||
backAzimuth: number;
|
||||
|
||||
@AutoMap()
|
||||
seatsDriver: number;
|
||||
|
||||
@AutoMap()
|
||||
seatsPassenger: number;
|
||||
|
||||
@AutoMap()
|
||||
seatsUsed: number;
|
||||
|
||||
@AutoMap()
|
||||
strict: boolean;
|
||||
|
||||
@AutoMap()
|
||||
createdAt: Date;
|
||||
|
||||
@AutoMap()
|
||||
updatedAt: Date;
|
||||
}
|
||||
92
old/modules/ad/domain/entities/geography.ts
Normal file
92
old/modules/ad/domain/entities/geography.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { Coordinate } from '../../../geography/domain/entities/coordinate';
|
||||
import { Route } from '../../../geography/domain/entities/route';
|
||||
import { Role } from '../types/role.enum';
|
||||
import { IGeorouter } from '../../../geography/domain/interfaces/georouter.interface';
|
||||
import { Path } from '../../../geography/domain/types/path.type';
|
||||
import { GeorouterSettings } from '../../../geography/domain/types/georouter-settings.type';
|
||||
|
||||
export class Geography {
|
||||
private coordinates: Coordinate[];
|
||||
driverRoute: Route;
|
||||
passengerRoute: Route;
|
||||
|
||||
constructor(coordinates: Coordinate[]) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
createRoutes = async (
|
||||
roles: Role[],
|
||||
georouter: IGeorouter,
|
||||
settings: GeorouterSettings,
|
||||
): Promise<void> => {
|
||||
const paths: Path[] = this.getPaths(roles);
|
||||
const routes = await georouter.route(paths, settings);
|
||||
if (routes.some((route) => route.key == RouteType.COMMON)) {
|
||||
this.driverRoute = routes.find(
|
||||
(route) => route.key == RouteType.COMMON,
|
||||
).route;
|
||||
this.passengerRoute = routes.find(
|
||||
(route) => route.key == RouteType.COMMON,
|
||||
).route;
|
||||
} else {
|
||||
if (routes.some((route) => route.key == RouteType.DRIVER)) {
|
||||
this.driverRoute = routes.find(
|
||||
(route) => route.key == RouteType.DRIVER,
|
||||
).route;
|
||||
}
|
||||
if (routes.some((route) => route.key == RouteType.PASSENGER)) {
|
||||
this.passengerRoute = routes.find(
|
||||
(route) => route.key == RouteType.PASSENGER,
|
||||
).route;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private getPaths = (roles: Role[]): Path[] => {
|
||||
const paths: Path[] = [];
|
||||
if (roles.includes(Role.DRIVER) && roles.includes(Role.PASSENGER)) {
|
||||
if (this.coordinates.length == 2) {
|
||||
// 2 points => same route for driver and passenger
|
||||
const commonPath: Path = {
|
||||
key: RouteType.COMMON,
|
||||
points: this.coordinates,
|
||||
};
|
||||
paths.push(commonPath);
|
||||
} else {
|
||||
const driverPath: Path = this.createDriverPath();
|
||||
const passengerPath: Path = this.createPassengerPath();
|
||||
paths.push(driverPath, passengerPath);
|
||||
}
|
||||
} else if (roles.includes(Role.DRIVER)) {
|
||||
const driverPath: Path = this.createDriverPath();
|
||||
paths.push(driverPath);
|
||||
} else if (roles.includes(Role.PASSENGER)) {
|
||||
const passengerPath: Path = this.createPassengerPath();
|
||||
paths.push(passengerPath);
|
||||
}
|
||||
return paths;
|
||||
};
|
||||
|
||||
private createDriverPath = (): Path => {
|
||||
return {
|
||||
key: RouteType.DRIVER,
|
||||
points: this.coordinates,
|
||||
};
|
||||
};
|
||||
|
||||
private createPassengerPath = (): Path => {
|
||||
return {
|
||||
key: RouteType.PASSENGER,
|
||||
points: [
|
||||
this.coordinates[0],
|
||||
this.coordinates[this.coordinates.length - 1],
|
||||
],
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export enum RouteType {
|
||||
COMMON = 'common',
|
||||
DRIVER = 'driver',
|
||||
PASSENGER = 'passenger',
|
||||
}
|
||||
19
old/modules/ad/domain/entities/time-converter.ts
Normal file
19
old/modules/ad/domain/entities/time-converter.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { DateTime, TimeZone } from 'timezonecomplete';
|
||||
|
||||
export class TimeConverter {
|
||||
static toUtcDatetime = (date: Date, time: string, timezone: string): Date => {
|
||||
try {
|
||||
if (!date || !time || !timezone) throw new Error();
|
||||
return new Date(
|
||||
new DateTime(
|
||||
`${date.toISOString().split('T')[0]}T${time}:00`,
|
||||
TimeZone.zone(timezone, false),
|
||||
)
|
||||
.convert(TimeZone.zone('UTC'))
|
||||
.toIsoString(),
|
||||
);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user