mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 08:22:41 +00:00
handle pagination on query
This commit is contained in:
@@ -16,4 +16,5 @@ export type DefaultParams = {
|
||||
AZIMUTH_MARGIN: number;
|
||||
MAX_DETOUR_DISTANCE_RATIO: number;
|
||||
MAX_DETOUR_DURATION_RATIO: number;
|
||||
PER_PAGE: number;
|
||||
};
|
||||
|
||||
@@ -49,6 +49,10 @@ export class MatchQueryHandler implements IQueryHandler {
|
||||
maxDetourDistanceRatio: this._defaultParams.MAX_DETOUR_DISTANCE_RATIO,
|
||||
maxDetourDurationRatio: this._defaultParams.MAX_DETOUR_DURATION_RATIO,
|
||||
})
|
||||
.setDefaultPagination({
|
||||
page: 1,
|
||||
perPage: this._defaultParams.PER_PAGE,
|
||||
})
|
||||
.setDatesAndSchedule(this.datetimeTransformer);
|
||||
await query.setRoutes();
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ export class MatchQuery extends QueryBase {
|
||||
azimuthMargin?: number;
|
||||
maxDetourDistanceRatio?: number;
|
||||
maxDetourDurationRatio?: number;
|
||||
readonly page?: number;
|
||||
readonly perPage?: number;
|
||||
page?: number;
|
||||
perPage?: number;
|
||||
driverRoute?: Route;
|
||||
passengerRoute?: Route;
|
||||
backAzimuth?: number;
|
||||
@@ -61,8 +61,8 @@ export class MatchQuery extends QueryBase {
|
||||
this.azimuthMargin = props.azimuthMargin;
|
||||
this.maxDetourDistanceRatio = props.maxDetourDistanceRatio;
|
||||
this.maxDetourDurationRatio = props.maxDetourDurationRatio;
|
||||
this.page = props.page ?? 1;
|
||||
this.perPage = props.perPage ?? 10;
|
||||
this.page = props.page;
|
||||
this.perPage = props.perPage;
|
||||
this.originWaypoint = this.waypoints.filter(
|
||||
(waypoint: Waypoint) => waypoint.position == 0,
|
||||
)[0];
|
||||
@@ -124,6 +124,12 @@ export class MatchQuery extends QueryBase {
|
||||
return this;
|
||||
};
|
||||
|
||||
setDefaultPagination = (defaultPagination: DefaultPagination): MatchQuery => {
|
||||
if (!this.page) this.page = defaultPagination.page;
|
||||
if (!this.perPage) this.perPage = defaultPagination.perPage;
|
||||
return this;
|
||||
};
|
||||
|
||||
setDatesAndSchedule = (
|
||||
datetimeTransformer: DateTimeTransformerPort,
|
||||
): MatchQuery => {
|
||||
@@ -243,3 +249,8 @@ interface DefaultAlgorithmParameters {
|
||||
maxDetourDistanceRatio: number;
|
||||
maxDetourDurationRatio: number;
|
||||
}
|
||||
|
||||
interface DefaultPagination {
|
||||
page: number;
|
||||
perPage: number;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ const USE_AZIMUTH = true;
|
||||
const AZIMUTH_MARGIN = 10;
|
||||
const MAX_DETOUR_DISTANCE_RATIO = 0.3;
|
||||
const MAX_DETOUR_DURATION_RATIO = 0.3;
|
||||
const PER_PAGE = 10;
|
||||
|
||||
@Injectable()
|
||||
export class DefaultParamsProvider implements DefaultParamsProviderPort {
|
||||
@@ -81,5 +82,9 @@ export class DefaultParamsProvider implements DefaultParamsProviderPort {
|
||||
this._configService.get('MAX_DETOUR_DURATION_RATIO') as string,
|
||||
)
|
||||
: MAX_DETOUR_DURATION_RATIO,
|
||||
PER_PAGE:
|
||||
this._configService.get('PER_PAGE') !== undefined
|
||||
? parseInt(this._configService.get('PER_PAGE') as string)
|
||||
: PER_PAGE,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||
AZIMUTH_MARGIN: 10,
|
||||
MAX_DETOUR_DISTANCE_RATIO: 0.3,
|
||||
MAX_DETOUR_DURATION_RATIO: 0.3,
|
||||
PER_PAGE: 10,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -49,6 +49,7 @@ const defaultParams: DefaultParams = {
|
||||
AZIMUTH_MARGIN: 10,
|
||||
MAX_DETOUR_DISTANCE_RATIO: 0.3,
|
||||
MAX_DETOUR_DURATION_RATIO: 0.3,
|
||||
PER_PAGE: 10,
|
||||
};
|
||||
|
||||
const mockInputDateTimeTransformer: DateTimeTransformerPort = {
|
||||
|
||||
@@ -34,6 +34,8 @@ const mockConfigServiceWithDefaults = {
|
||||
return 0.5;
|
||||
case 'MAX_DETOUR_DURATION_RATIO':
|
||||
return 0.6;
|
||||
case 'PER_PAGE':
|
||||
return 15;
|
||||
default:
|
||||
return 'some_default_value';
|
||||
}
|
||||
@@ -96,6 +98,7 @@ describe('DefaultParamsProvider', () => {
|
||||
expect(params.AZIMUTH_MARGIN).toBe(15);
|
||||
expect(params.MAX_DETOUR_DISTANCE_RATIO).toBe(0.5);
|
||||
expect(params.MAX_DETOUR_DURATION_RATIO).toBe(0.6);
|
||||
expect(params.PER_PAGE).toBe(15);
|
||||
});
|
||||
|
||||
it('should provide default params if defaults are not set', async () => {
|
||||
@@ -113,5 +116,6 @@ describe('DefaultParamsProvider', () => {
|
||||
expect(params.AZIMUTH_MARGIN).toBe(10);
|
||||
expect(params.MAX_DETOUR_DISTANCE_RATIO).toBe(0.3);
|
||||
expect(params.MAX_DETOUR_DURATION_RATIO).toBe(0.3);
|
||||
expect(params.PER_PAGE).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||
AZIMUTH_MARGIN: 10,
|
||||
MAX_DETOUR_DISTANCE_RATIO: 0.3,
|
||||
MAX_DETOUR_DURATION_RATIO: 0.3,
|
||||
PER_PAGE: 10,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = {
|
||||
AZIMUTH_MARGIN: 10,
|
||||
MAX_DETOUR_DISTANCE_RATIO: 0.3,
|
||||
MAX_DETOUR_DURATION_RATIO: 0.3,
|
||||
PER_PAGE: 10,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user