add default timezone

This commit is contained in:
sbriat 2023-04-12 08:47:38 +02:00
parent b90db67ed0
commit c396da77fc
7 changed files with 96 additions and 65 deletions

View File

@ -4,6 +4,12 @@ SERVICE_PORT=5005
SERVICE_CONFIGURATION_DOMAIN=MATCHER SERVICE_CONFIGURATION_DOMAIN=MATCHER
HEALTH_SERVICE_PORT=6005 HEALTH_SERVICE_PORT=6005
# DEFAULT CONFIGURATION
DEFAULT_IDENTIFIER=0
MARGIN_DURATION=900
VALIDITY_DURATION=365
DEFAULT_TIMEZONE=Europe/Paris
# PRISMA # PRISMA
DATABASE_URL="postgresql://mobicoop:mobicoop@v3-db:5432/mobicoop?schema=matcher" DATABASE_URL="postgresql://mobicoop:mobicoop@v3-db:5432/mobicoop?schema=matcher"

View File

@ -13,6 +13,7 @@ export class DefaultParamsProvider {
), ),
MARGIN_DURATION: parseInt(this.configService.get('MARGIN_DURATION')), MARGIN_DURATION: parseInt(this.configService.get('MARGIN_DURATION')),
VALIDITY_DURATION: parseInt(this.configService.get('VALIDITY_DURATION')), VALIDITY_DURATION: parseInt(this.configService.get('VALIDITY_DURATION')),
DEFAULT_TIMEZONE: this.configService.get('DEFAULT_TIMEZONE'),
}; };
} }
} }

View File

@ -11,20 +11,21 @@ export class Geography {
waypoints: Array<Waypoint>; waypoints: Array<Waypoint>;
originType: PointType; originType: PointType;
destinationType: PointType; destinationType: PointType;
timeZones: Array<string>; timezones: Array<string>;
driverRoute: Route; driverRoute: Route;
passengerRoute: Route; passengerRoute: Route;
constructor(geographyRequest: IRequestGeography) { constructor(geographyRequest: IRequestGeography, defaultTimezone: string) {
this._geographyRequest = geographyRequest; this._geographyRequest = geographyRequest;
this.waypoints = []; this.waypoints = [];
this.originType = PointType.OTHER; this.originType = PointType.OTHER;
this.destinationType = PointType.OTHER; this.destinationType = PointType.OTHER;
this.timezones = [defaultTimezone];
} }
init() { init() {
this._validateWaypoints(); this._validateWaypoints();
this._setTimeZones(); this._setTimezones();
} }
_validateWaypoints() { _validateWaypoints() {
@ -45,8 +46,8 @@ export class Geography {
}); });
} }
_setTimeZones() { _setTimezones() {
this.timeZones = find( this.timezones = find(
this._geographyRequest.waypoints[0].lat, this._geographyRequest.waypoints[0].lat,
this._geographyRequest.waypoints[0].lon, this._geographyRequest.waypoints[0].lon,
); );

View File

@ -2,4 +2,5 @@ export type IDefaultParams = {
DEFAULT_IDENTIFIER: number; DEFAULT_IDENTIFIER: number;
MARGIN_DURATION: number; MARGIN_DURATION: number;
VALIDITY_DURATION: number; VALIDITY_DURATION: number;
DEFAULT_TIMEZONE: string;
}; };

View File

@ -60,7 +60,10 @@ export class MatchQuery {
} }
_setGeography() { _setGeography() {
this.geography = new Geography(this._matchRequest); this.geography = new Geography(
this._matchRequest,
this._defaultParams.DEFAULT_TIMEZONE,
);
this.geography.init(); this.geography.init();
} }

View File

@ -2,83 +2,101 @@ import { Geography } from '../../domain/entities/geography';
describe('Geography entity', () => { describe('Geography entity', () => {
it('should be defined', () => { it('should be defined', () => {
const geography = new Geography({ const geography = new Geography(
waypoints: [ {
{ waypoints: [
lat: 49.440041, {
lon: 1.093912, lat: 49.440041,
}, lon: 1.093912,
{ },
lat: 50.630992, {
lon: 3.045432, lat: 50.630992,
}, lon: 3.045432,
], },
}); ],
},
'Europe/Paris',
);
expect(geography).toBeDefined(); expect(geography).toBeDefined();
}); });
describe('init', () => { describe('init', () => {
it('should initialize a geography request', () => { it('should initialize a geography request', () => {
const geography = new Geography({ const geography = new Geography(
waypoints: [ {
{ waypoints: [
lat: 49.440041, {
lon: 1.093912, lat: 49.440041,
}, lon: 1.093912,
{ },
lat: 50.630992, {
lon: 3.045432, lat: 50.630992,
}, lon: 3.045432,
], },
}); ],
},
'Europe/Paris',
);
geography.init(); geography.init();
expect(geography.waypoints.length).toBe(2); expect(geography.waypoints.length).toBe(2);
}); });
it('should throw an exception if waypoints are empty', () => { it('should throw an exception if waypoints are empty', () => {
const geography = new Geography({ const geography = new Geography(
waypoints: [], {
}); waypoints: [],
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow(); expect(() => geography.init()).toThrow();
}); });
it('should throw an exception if only one waypoint is provided', () => { it('should throw an exception if only one waypoint is provided', () => {
const geography = new Geography({ const geography = new Geography(
waypoints: [ {
{ waypoints: [
lat: 49.440041, {
lon: 1.093912, lat: 49.440041,
}, lon: 1.093912,
], },
}); ],
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow(); expect(() => geography.init()).toThrow();
}); });
it('should throw an exception if a waypoint has invalid longitude', () => { it('should throw an exception if a waypoint has invalid longitude', () => {
const geography = new Geography({ const geography = new Geography(
waypoints: [ {
{ waypoints: [
lat: 49.440041, {
lon: 201.093912, lat: 49.440041,
}, lon: 201.093912,
{ },
lat: 50.630992, {
lon: 3.045432, lat: 50.630992,
}, lon: 3.045432,
], },
}); ],
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow(); expect(() => geography.init()).toThrow();
}); });
it('should throw an exception if a waypoint has invalid latitude', () => { it('should throw an exception if a waypoint has invalid latitude', () => {
const geography = new Geography({ const geography = new Geography(
waypoints: [ {
{ waypoints: [
lat: 49.440041, {
lon: 1.093912, lat: 49.440041,
}, lon: 1.093912,
{ },
lat: 250.630992, {
lon: 3.045432, lat: 250.630992,
}, lon: 3.045432,
], },
}); ],
},
'Europe/Paris',
);
expect(() => geography.init()).toThrow(); expect(() => geography.init()).toThrow();
}); });
}); });

View File

@ -18,6 +18,7 @@ const defaultParams: IDefaultParams = {
DEFAULT_IDENTIFIER: 0, DEFAULT_IDENTIFIER: 0,
MARGIN_DURATION: 900, MARGIN_DURATION: 900,
VALIDITY_DURATION: 365, VALIDITY_DURATION: 365,
DEFAULT_TIMEZONE: 'Europe/Paris',
}; };
describe('MatchUseCase', () => { describe('MatchUseCase', () => {