Skip to content

Commit

Permalink
Add all strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Jan 11, 2025
1 parent abc1c4a commit 11b7590
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
34 changes: 26 additions & 8 deletions api/src/modules/geo-coding/geo-coding.service-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { CacheManager } from './cache.manager';
import { GeocoderService } from './geocoders/geocoder.service';
import { CountryOfProductionGeoCodingStrategy } from './strategies_v2/country-of-production.geocoding.service';
import { GeocodingRepository } from './strategies_v2/geocoding.repository';
import { AdminRegionOfProductionGeocodingStrategy } from './strategies_v2/admin-region-of-production.service';
import { AggregationPointGeocodingStrategy } from './strategies_v2/aggregation-point.geocoding.service';

/**
* @description: Custom repository for GeoCoding that handles all queries in a single transaction, due to changes in typeorm 0.2.x, not allowing
Expand All @@ -43,7 +45,7 @@ export class GeoCodedLocation {
export class GeoCodingServiceV2 {
queryRunner: QueryRunner | null;
manager: EntityManager;
strategies: Record<any, IGeoCodingStrategy>;
strategies: Record<LOCATION_TYPES, IGeoCodingStrategy>;
logger: Logger = new Logger(GeoCodingServiceV2.name);

constructor(
Expand Down Expand Up @@ -81,14 +83,30 @@ export class GeoCodingServiceV2 {
}

private loadStrategies(repository: GeocodingRepository): void {
const unknownLocationStrategy = new UnknownLocationGeoCodingStrategy(
repository,
);
const pointOfProductionStrategy = new PointOfProductionGeocodingStrategy(
repository,
this.geocoder,
);
const countryOfProductionStrategy =
new CountryOfProductionGeoCodingStrategy(repository);
const aggregationPointStrategy = new AggregationPointGeocodingStrategy(
repository,
this.geocoder,
);
const adminRegionOfProductionStrategy =
new AdminRegionOfProductionGeocodingStrategy(repository);

this.strategies = {
[LOCATION_TYPES.UNKNOWN]: new UnknownLocationGeoCodingStrategy(
repository,
),
[LOCATION_TYPES.POINT_OF_PRODUCTION]:
new PointOfProductionGeocodingStrategy(repository, this.geocoder),
[LOCATION_TYPES.COUNTRY_OF_PRODUCTION]:
new CountryOfProductionGeoCodingStrategy(repository),
[LOCATION_TYPES.UNKNOWN]: unknownLocationStrategy,
[LOCATION_TYPES.POINT_OF_PRODUCTION]: pointOfProductionStrategy,
[LOCATION_TYPES.COUNTRY_OF_PRODUCTION]: countryOfProductionStrategy,
[LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT]: aggregationPointStrategy,
[LOCATION_TYPES.ADMINISTRATIVE_REGION_OF_PRODUCTION]:
adminRegionOfProductionStrategy,
[LOCATION_TYPES.COUNTRY_OF_DELIVERY]: unknownLocationStrategy,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
} from '../geo-coding.service-v2';
import { GeocodingRepository } from './geocoding.repository';

@Injectable()
export class AdminRegionOfProductionService implements IGeoCodingStrategy {
export class AdminRegionOfProductionGeocodingStrategy
implements IGeoCodingStrategy
{
repo: GeocodingRepository;

constructor(geocodingRepository: GeocodingRepository) {
Expand Down

0 comments on commit 11b7590

Please sign in to comment.