handle pagination on query
This commit is contained in:
parent
3bc142f4f7
commit
5c802df529
15
.env.dist
15
.env.dist
|
@ -47,19 +47,16 @@ MAX_DETOUR_DURATION_RATIO=0.3
|
|||
GEOROUTER_TYPE=graphhopper
|
||||
# georouter url
|
||||
GEOROUTER_URL=http://localhost:8989
|
||||
|
||||
# DEFAULT CARPOOL DEPARTURE TIME MARGIN (in seconds)
|
||||
# default carpool departure time margin (in seconds)
|
||||
DEPARTURE_TIME_MARGIN=900
|
||||
|
||||
# DEFAULT ROLE
|
||||
# default role
|
||||
ROLE=passenger
|
||||
|
||||
# SEATS PROPOSED AS DRIVER / REQUESTED AS PASSENGER
|
||||
# seats proposes as driver / requested as passenger
|
||||
SEATS_PROPOSED=3
|
||||
SEATS_REQUESTED=1
|
||||
|
||||
# ACCEPT ONLY SAME FREQUENCY REQUESTS
|
||||
# accept only same frequency requests
|
||||
STRICT_FREQUENCY=false
|
||||
|
||||
# default timezone
|
||||
TIMEZONE=Europe/Paris
|
||||
# number of matching results per page
|
||||
PER_PAGE=10
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue