mirror of
https://gitlab.com/mobicoop/v3/service/configuration.git
synced 2026-01-09 16:32:40 +00:00
add match config
This commit is contained in:
@@ -3,6 +3,7 @@ import { Config } from './config';
|
||||
|
||||
export interface CarpoolConfig extends Config {
|
||||
departureTimeMargin: number;
|
||||
recurrentAdValidityDuration: number;
|
||||
role: string;
|
||||
seatsProposed: number;
|
||||
seatsRequested: number;
|
||||
@@ -13,6 +14,9 @@ export default registerAs('carpool', () => ({
|
||||
departureTimeMargin: process.env.DEPARTURE_TIME_MARGIN
|
||||
? parseInt(process.env.DEPARTURE_TIME_MARGIN, 10)
|
||||
: 900,
|
||||
recurrentAdValidityDuration: process.env.RECURRENT_AD_VALIDITY_DURATION
|
||||
? parseInt(process.env.RECURRENT_AD_VALIDITY_DURATION, 10)
|
||||
: 365,
|
||||
role: process.env.ROLE ?? 'passenger',
|
||||
seatsProposed: process.env.SEATS_PROPOSED
|
||||
? parseInt(process.env.SEATS_PROPOSED, 10)
|
||||
|
||||
40
src/config/match.config.ts
Normal file
40
src/config/match.config.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { registerAs } from '@nestjs/config';
|
||||
import { Config } from './config';
|
||||
|
||||
export interface MatchConfig extends Config {
|
||||
algorithm: string;
|
||||
remoteness: number;
|
||||
useProportion: boolean;
|
||||
proportion: number;
|
||||
useAzimuth: boolean;
|
||||
azimuthMargin: number;
|
||||
maxDetourDistanceRatio: number;
|
||||
maxDetourDurationRatio: number;
|
||||
}
|
||||
|
||||
export default registerAs('match', () => ({
|
||||
algorithm: process.env.ALGORITHM ?? 'PASSENGER_ORIENTED',
|
||||
remoteness: process.env.REMOTENESS
|
||||
? parseInt(process.env.REMOTENESS, 10)
|
||||
: 15000,
|
||||
useProportion: process.env.USE_PROPORTION
|
||||
? process.env.USE_PROPORTION === 'false'
|
||||
? false
|
||||
: true
|
||||
: true,
|
||||
proportion: process.env.PROPORTION ? parseFloat(process.env.PROPORTION) : 0.3,
|
||||
useAzimuth: process.env.USE_AZIMUTH
|
||||
? process.env.USE_AZIMUTH === 'false'
|
||||
? false
|
||||
: true
|
||||
: true,
|
||||
azimuthMargin: process.env.AZIMUTH_MARGIN
|
||||
? parseInt(process.env.AZIMUTH_MARGIN, 10)
|
||||
: 10,
|
||||
maxDetourDistanceRatio: process.env.MAX_DETOUR_DISTANCE_RATIO
|
||||
? parseFloat(process.env.MAX_DETOUR_DISTANCE_RATIO)
|
||||
: 0.3,
|
||||
maxDetourDurationRatio: process.env.MAX_DETOUR_DURATION_RATIO
|
||||
? parseFloat(process.env.MAX_DETOUR_DURATION_RATIO)
|
||||
: 0.3,
|
||||
}));
|
||||
@@ -31,7 +31,8 @@ export class SetConfigurationService implements ICommandHandler {
|
||||
);
|
||||
if (isNaN(value)) throw new ArgumentInvalidException('Bad value');
|
||||
return await this.configurationRepository.set(
|
||||
command.configurationIdentifier,
|
||||
command.configurationIdentifier.domain,
|
||||
command.configurationIdentifier.key,
|
||||
value,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ export class GetConfigurationQueryHandler implements IQueryHandler {
|
||||
) {}
|
||||
async execute(query: GetConfigurationQuery): Promise<ConfigurationValue> {
|
||||
return await this.configurationRepository.get(
|
||||
query.configurationIdentifier,
|
||||
query.configurationIdentifier.domain,
|
||||
query.configurationIdentifier.key,
|
||||
this.configurationsManager.identifierType(query.configurationIdentifier),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { CarpoolConfig } from '@src/config/carpool.config';
|
||||
import { Config } from '@src/config/config';
|
||||
import { MatchConfig } from '@src/config/match.config';
|
||||
import { PaginationConfig } from '@src/config/pagination.config';
|
||||
|
||||
@Injectable()
|
||||
@@ -21,6 +22,10 @@ export class ConfigurationsManagerService {
|
||||
...(this.configService.get<CarpoolConfig>('carpool') as CarpoolConfig),
|
||||
domain: ConfigurationDomain.CARPOOL,
|
||||
},
|
||||
{
|
||||
...(this.configService.get<MatchConfig>('match') as MatchConfig),
|
||||
domain: ConfigurationDomain.MATCH,
|
||||
},
|
||||
{
|
||||
...(this.configService.get<PaginationConfig>(
|
||||
'pagination',
|
||||
|
||||
@@ -36,19 +36,15 @@ export class PopulateService implements OnApplicationBootstrap {
|
||||
try {
|
||||
if (key !== 'domain')
|
||||
await this.getConfigurationRepository.get(
|
||||
{
|
||||
domain: config.domain,
|
||||
key,
|
||||
},
|
||||
config.domain,
|
||||
key,
|
||||
this.configurationsManager.configurationType(configuration[key]),
|
||||
);
|
||||
} catch (error: any) {
|
||||
if (error instanceof NotFoundException) {
|
||||
this.setConfigurationRepository.set(
|
||||
{
|
||||
domain: config.domain,
|
||||
key,
|
||||
},
|
||||
config.domain,
|
||||
key,
|
||||
`${configuration[key]}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,17 @@ const mockConfigService = {
|
||||
seatsRequested: 1,
|
||||
strictFrequency: false,
|
||||
};
|
||||
case 'match':
|
||||
return {
|
||||
algorithm: 'PASSENGER_ORIENTED',
|
||||
remoteness: 15000,
|
||||
useProportion: true,
|
||||
proportion: 0.3,
|
||||
useAzimuth: true,
|
||||
azimuthMargin: 10,
|
||||
maxDetourDistanceRatio: 0.3,
|
||||
maxDetourDurationRatio: 0.3,
|
||||
};
|
||||
case 'pagination':
|
||||
return {
|
||||
perPage: 10,
|
||||
@@ -53,7 +64,7 @@ describe('Configurations Manager Service', () => {
|
||||
|
||||
it('should return the list of configuration elements', () => {
|
||||
const list: Config[] = configurationsManagerService.list();
|
||||
expect(list).toHaveLength(2);
|
||||
expect(list).toHaveLength(3);
|
||||
});
|
||||
|
||||
describe('identifierType', () => {
|
||||
@@ -68,8 +79,8 @@ describe('Configurations Manager Service', () => {
|
||||
});
|
||||
it('should throw if configuration item is not found', () => {
|
||||
const configurationIdentifier: ConfigurationIdentifier = {
|
||||
domain: ConfigurationDomain.CARPOOL,
|
||||
key: 'minAge',
|
||||
domain: ConfigurationDomain.MATCH,
|
||||
key: 'maxDetour',
|
||||
};
|
||||
expect(() => {
|
||||
configurationsManagerService.identifierType(configurationIdentifier);
|
||||
|
||||
Reference in New Issue
Block a user