Skip to content

Commit

Permalink
update location types to handle new xlsx version
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Nov 28, 2022
1 parent f0e7f1f commit c0fce28
Show file tree
Hide file tree
Showing 36 changed files with 294 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import {
IsUUID,
} from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import {
LOCATION_TYPES,
LOCATION_TYPES_PARAMS,
} from 'modules/sourcing-locations/sourcing-location.entity';
import { transformLocationType } from 'utils/transform-location-type.util';
import { Type } from 'class-transformer';
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';

export class GetAdminRegionTreeWithOptionsDto {
@ApiPropertyOptional({
Expand Down Expand Up @@ -55,21 +51,18 @@ export class GetAdminRegionTreeWithOptionsDto {

@ApiPropertyOptional({
description: 'Types of Sourcing Locations, written with hyphens',
enum: Object.values(LOCATION_TYPES_PARAMS),
enum: Object.values(LOCATION_TYPES),
name: 'locationTypes[]',
})
@IsOptional()
@IsEnum(LOCATION_TYPES, {
each: true,
message:
'Available options: ' +
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
Object.values(LOCATION_TYPES).toString().toLowerCase(),
})
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
transformLocationType(value),
)
@Type(() => String)
locationTypes?: LOCATION_TYPES_PARAMS[];
locationTypes?: LOCATION_TYPES[];

@ApiPropertyOptional()
@IsOptional()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import {
IsUUID,
} from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import {
LOCATION_TYPES,
LOCATION_TYPES_PARAMS,
} from 'modules/sourcing-locations/sourcing-location.entity';
import { transformLocationType } from 'utils/transform-location-type.util';
import { Type } from 'class-transformer';
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';
import { replaceStringWhiteSpacesWithDash } from 'utils/transform-location-type.util';

export class GetBusinessUnitTreeWithOptionsDto {
@ApiPropertyOptional({
Expand Down Expand Up @@ -50,21 +47,20 @@ export class GetBusinessUnitTreeWithOptionsDto {

@ApiPropertyOptional({
description: 'Types of Sourcing Locations, written with hyphens',
enum: Object.values(LOCATION_TYPES_PARAMS),
enum: Object.values(LOCATION_TYPES),
name: 'locationTypes[]',
})
@IsOptional()
@IsEnum(LOCATION_TYPES, {
each: true,
message:
'Available options: ' +
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
replaceStringWhiteSpacesWithDash(
Object.values(LOCATION_TYPES).toString().toLowerCase(),
),
})
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
transformLocationType(value),
)
@Type(() => String)
locationTypes?: LOCATION_TYPES_PARAMS[];
locationTypes?: LOCATION_TYPES[];

@ApiPropertyOptional()
@IsOptional()
Expand Down
8 changes: 6 additions & 2 deletions api/src/modules/geo-coding/geo-coding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export class GeoCodingService extends GeoCodingAbstractClass {
);
}

if (location.locationType === LOCATION_TYPES.AGGREGATION_POINT) {
if (
location.locationType === LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT
) {
geoCodedSourcingData.push(await this.geoCodeAggregationPoint(location));
}
if (location.locationType === LOCATION_TYPES.POINT_OF_PRODUCTION) {
Expand Down Expand Up @@ -89,7 +91,9 @@ export class GeoCodingService extends GeoCodingAbstractClass {
)) as SourcingData;
}

if (locationInfo.locationType === LOCATION_TYPES.AGGREGATION_POINT) {
if (
locationInfo.locationType === LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT
) {
geoCodedSourcingLocation = (await this.geoCodeAggregationPoint(
locationInfo as SourcingData,
)) as SourcingData;
Expand Down
15 changes: 4 additions & 11 deletions api/src/modules/h3-data/dto/get-impact-map.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { AvailableResolutions } from 'modules/h3-data/dto/get-material-h3-by-resolution.dto';
import {
LOCATION_TYPES,
LOCATION_TYPES_PARAMS,
} from 'modules/sourcing-locations/sourcing-location.entity';
import { transformLocationType } from 'utils/transform-location-type.util';
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';

export enum GROUP_BY_VALUES {
MATERIAL = 'material',
Expand Down Expand Up @@ -67,21 +63,18 @@ class BaseGetImpactMapDto {

@ApiPropertyOptional({
description: 'Types of Sourcing Locations, written with hyphens',
enum: Object.values(LOCATION_TYPES_PARAMS),
enum: Object.values(LOCATION_TYPES),
name: 'locationTypes[]',
})
@IsOptional()
@IsEnum(LOCATION_TYPES, {
each: true,
message:
'Available options: ' +
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
Object.values(LOCATION_TYPES).toString().toLowerCase(),
})
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
transformLocationType(value),
)
@Type(() => String)
locationTypes?: LOCATION_TYPES_PARAMS[];
locationTypes?: LOCATION_TYPES[];
}

export class GetImpactMapDto extends BaseGetImpactMapDto {
Expand Down
4 changes: 2 additions & 2 deletions api/src/modules/h3-data/h3-data-map.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from 'modules/h3-data/h3-data.entity';
import { Logger, ServiceUnavailableException } from '@nestjs/common';
import {
LOCATION_TYPES_PARAMS,
LOCATION_TYPES,
SourcingLocation,
} from 'modules/sourcing-locations/sourcing-location.entity';
import { SourcingRecord } from 'modules/sourcing-records/sourcing-record.entity';
Expand Down Expand Up @@ -315,7 +315,7 @@ export class H3DataMapRepository extends Repository<H3Data> {
materialIds?: string[],
originIds?: string[],
supplierIds?: string[],
locationTypes?: LOCATION_TYPES_PARAMS[],
locationTypes?: LOCATION_TYPES[],
baseQueryExtend?: (baseQuery: SelectQueryBuilder<any>) => void,
scenarioComparisonQuantiles?: boolean,
): Promise<{ impactMap: H3IndexValueData[]; quantiles: number[] }> {
Expand Down
17 changes: 7 additions & 10 deletions api/src/modules/impact/dto/impact-table.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';

import { GROUP_BY_VALUES } from 'modules/h3-data/dto/get-impact-map.dto';
import {
LOCATION_TYPES,
LOCATION_TYPES_PARAMS,
} from 'modules/sourcing-locations/sourcing-location.entity';
import { transformLocationType } from 'utils/transform-location-type.util';
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';
import { replaceStringWhiteSpacesWithDash } from 'utils/transform-location-type.util';

export class BaseImpactTableDto {
@ApiProperty({
Expand Down Expand Up @@ -71,21 +68,21 @@ export class BaseImpactTableDto {

@ApiPropertyOptional({
description: 'Types of Sourcing Locations, written with hyphens',
enum: Object.values(LOCATION_TYPES_PARAMS),
enum: Object.values(LOCATION_TYPES),
name: 'locationTypes[]',
})
@IsOptional()
@IsEnum(LOCATION_TYPES, {
each: true,
message:
'Available options: ' +
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
Object.values(LOCATION_TYPES).toString().toLowerCase(),
})
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
transformLocationType(value),
@Transform(({ value }: { value: LOCATION_TYPES[] }) =>
replaceStringWhiteSpacesWithDash(value),
)
@Type(() => String)
locationTypes?: LOCATION_TYPES_PARAMS[];
locationTypes?: LOCATION_TYPES[];
}

export class GetActualVsScenarioImpactTableDto extends BaseImpactTableDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { SourcingDataExcelValidator } from 'modules/import-data/sourcing-data/va
import { validateOrReject } from 'class-validator';
import { plainToClass } from 'class-transformer';
import { CreateIndicatorDto } from 'modules/indicators/dto/create.indicator.dto';
import { replaceStringWhiteSpacesWithDash } from 'utils/transform-location-type.util';
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';

/**
* @debt: Define a more accurate DTO / Interface / Class for API-DB trades
Expand Down Expand Up @@ -370,7 +372,9 @@ export class SourcingRecordsDtoProcessorService {
): CreateSourcingLocationDto {
const sourcingLocationDto: CreateSourcingLocationDto =
new CreateSourcingLocationDto();
sourcingLocationDto.locationType = sourcingLocationData.location_type;
sourcingLocationDto.locationType = replaceStringWhiteSpacesWithDash(
sourcingLocationData.location_type,
) as LOCATION_TYPES;
sourcingLocationDto.locationCountryInput =
sourcingLocationData.location_country_input;
sourcingLocationDto.locationAddressInput =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class LocationAddressInputValidator
return !addressInput;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
((args.object as SourcingDataExcelValidator).location_latitude_input ||
Expand All @@ -29,7 +29,7 @@ export class LocationAddressInputValidator
return !addressInput;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
(!(args.object as SourcingDataExcelValidator).location_latitude_input ||
Expand All @@ -52,7 +52,7 @@ export class LocationAddressInputValidator
}`;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
((args.object as SourcingDataExcelValidator).location_latitude_input ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export class LocationLatitudeInputValidator
return !latitudeInput;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
(args.object as SourcingDataExcelValidator).location_address_input
) {
return !latitudeInput;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
!(args.object as SourcingDataExcelValidator).location_address_input
Expand All @@ -50,7 +50,7 @@ export class LocationLatitudeInputValidator
}`;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
(args.object as SourcingDataExcelValidator).location_address_input
Expand All @@ -60,7 +60,7 @@ export class LocationLatitudeInputValidator
}. Latitude must be empty if address is provided`;
} else if (
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export class LocationLongitudeInputValidator
return !longitudeInput;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
(args.object as SourcingDataExcelValidator).location_address_input
) {
return !longitudeInput;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
!(args.object as SourcingDataExcelValidator).location_address_input
Expand All @@ -50,7 +50,7 @@ export class LocationLongitudeInputValidator
}`;
} else if (
((args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.AGGREGATION_POINT ||
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
(args.object as SourcingDataExcelValidator).location_type ===
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
(args.object as SourcingDataExcelValidator).location_address_input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ export class SourcingDataExcelValidator {
message:
'New location type input is required for the selected intervention type',
})
@IsEnum(Object.values(LOCATION_TYPES), {
message: `Available columns for new location type: ${Object.values(
LOCATION_TYPES,
).join(', ')}`,
})
@IsEnum(
Object.values(LOCATION_TYPES).map((s: string) => s.replace(/-/g, ' ')),
{
message: `Available columns for new location type: ${Object.values(
LOCATION_TYPES,
).join(', ')}`,
},
)
'location_type': LOCATION_TYPES;

@IsNotEmpty({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import {
IsUUID,
} from 'class-validator';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import {
LOCATION_TYPES,
LOCATION_TYPES_PARAMS,
} from 'modules/sourcing-locations/sourcing-location.entity';
import { transformLocationType } from 'utils/transform-location-type.util';
import { Type } from 'class-transformer';
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';

export class GetMaterialTreeWithOptionsDto {
@ApiPropertyOptional({
Expand Down Expand Up @@ -55,21 +51,18 @@ export class GetMaterialTreeWithOptionsDto {

@ApiPropertyOptional({
description: 'Types of Sourcing Locations, written with hyphens',
enum: Object.values(LOCATION_TYPES_PARAMS),
enum: Object.values(LOCATION_TYPES),
name: 'locationTypes[]',
})
@IsOptional()
@IsEnum(LOCATION_TYPES, {
each: true,
message:
'Available options: ' +
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
Object.values(LOCATION_TYPES).toString().toLowerCase(),
})
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
transformLocationType(value),
)
@Type(() => String)
locationTypes?: LOCATION_TYPES_PARAMS[];
locationTypes?: LOCATION_TYPES[];

@ApiPropertyOptional()
@IsOptional()
Expand Down
Loading

0 comments on commit c0fce28

Please sign in to comment.