Skip to content

Commit c0fce28

Browse files
committed
update location types to handle new xlsx version
1 parent f0e7f1f commit c0fce28

36 files changed

Lines changed: 294 additions & 274 deletions

File tree

api/src/modules/admin-regions/dto/get-admin-region-tree-with-options.dto.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ import {
99
IsUUID,
1010
} from 'class-validator';
1111
import { ApiPropertyOptional } from '@nestjs/swagger';
12-
import { Transform, Type } from 'class-transformer';
13-
import {
14-
LOCATION_TYPES,
15-
LOCATION_TYPES_PARAMS,
16-
} from 'modules/sourcing-locations/sourcing-location.entity';
17-
import { transformLocationType } from 'utils/transform-location-type.util';
12+
import { Type } from 'class-transformer';
13+
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';
1814

1915
export class GetAdminRegionTreeWithOptionsDto {
2016
@ApiPropertyOptional({
@@ -55,21 +51,18 @@ export class GetAdminRegionTreeWithOptionsDto {
5551

5652
@ApiPropertyOptional({
5753
description: 'Types of Sourcing Locations, written with hyphens',
58-
enum: Object.values(LOCATION_TYPES_PARAMS),
54+
enum: Object.values(LOCATION_TYPES),
5955
name: 'locationTypes[]',
6056
})
6157
@IsOptional()
6258
@IsEnum(LOCATION_TYPES, {
6359
each: true,
6460
message:
6561
'Available options: ' +
66-
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
62+
Object.values(LOCATION_TYPES).toString().toLowerCase(),
6763
})
68-
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
69-
transformLocationType(value),
70-
)
7164
@Type(() => String)
72-
locationTypes?: LOCATION_TYPES_PARAMS[];
65+
locationTypes?: LOCATION_TYPES[];
7366

7467
@ApiPropertyOptional()
7568
@IsOptional()

api/src/modules/business-units/dto/get-business-unit-tree-with-options.dto.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ import {
99
IsUUID,
1010
} from 'class-validator';
1111
import { ApiPropertyOptional } from '@nestjs/swagger';
12-
import { Transform, Type } from 'class-transformer';
13-
import {
14-
LOCATION_TYPES,
15-
LOCATION_TYPES_PARAMS,
16-
} from 'modules/sourcing-locations/sourcing-location.entity';
17-
import { transformLocationType } from 'utils/transform-location-type.util';
12+
import { Type } from 'class-transformer';
13+
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';
14+
import { replaceStringWhiteSpacesWithDash } from 'utils/transform-location-type.util';
1815

1916
export class GetBusinessUnitTreeWithOptionsDto {
2017
@ApiPropertyOptional({
@@ -50,21 +47,20 @@ export class GetBusinessUnitTreeWithOptionsDto {
5047

5148
@ApiPropertyOptional({
5249
description: 'Types of Sourcing Locations, written with hyphens',
53-
enum: Object.values(LOCATION_TYPES_PARAMS),
50+
enum: Object.values(LOCATION_TYPES),
5451
name: 'locationTypes[]',
5552
})
5653
@IsOptional()
5754
@IsEnum(LOCATION_TYPES, {
5855
each: true,
5956
message:
6057
'Available options: ' +
61-
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
58+
replaceStringWhiteSpacesWithDash(
59+
Object.values(LOCATION_TYPES).toString().toLowerCase(),
60+
),
6261
})
63-
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
64-
transformLocationType(value),
65-
)
6662
@Type(() => String)
67-
locationTypes?: LOCATION_TYPES_PARAMS[];
63+
locationTypes?: LOCATION_TYPES[];
6864

6965
@ApiPropertyOptional()
7066
@IsOptional()

api/src/modules/geo-coding/geo-coding.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export class GeoCodingService extends GeoCodingAbstractClass {
4444
);
4545
}
4646

47-
if (location.locationType === LOCATION_TYPES.AGGREGATION_POINT) {
47+
if (
48+
location.locationType === LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT
49+
) {
4850
geoCodedSourcingData.push(await this.geoCodeAggregationPoint(location));
4951
}
5052
if (location.locationType === LOCATION_TYPES.POINT_OF_PRODUCTION) {
@@ -89,7 +91,9 @@ export class GeoCodingService extends GeoCodingAbstractClass {
8991
)) as SourcingData;
9092
}
9193

92-
if (locationInfo.locationType === LOCATION_TYPES.AGGREGATION_POINT) {
94+
if (
95+
locationInfo.locationType === LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT
96+
) {
9397
geoCodedSourcingLocation = (await this.geoCodeAggregationPoint(
9498
locationInfo as SourcingData,
9599
)) as SourcingData;

api/src/modules/h3-data/dto/get-impact-map.dto.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ import {
1111
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
1212
import { Transform, Type } from 'class-transformer';
1313
import { AvailableResolutions } from 'modules/h3-data/dto/get-material-h3-by-resolution.dto';
14-
import {
15-
LOCATION_TYPES,
16-
LOCATION_TYPES_PARAMS,
17-
} from 'modules/sourcing-locations/sourcing-location.entity';
18-
import { transformLocationType } from 'utils/transform-location-type.util';
14+
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';
1915

2016
export enum GROUP_BY_VALUES {
2117
MATERIAL = 'material',
@@ -67,21 +63,18 @@ class BaseGetImpactMapDto {
6763

6864
@ApiPropertyOptional({
6965
description: 'Types of Sourcing Locations, written with hyphens',
70-
enum: Object.values(LOCATION_TYPES_PARAMS),
66+
enum: Object.values(LOCATION_TYPES),
7167
name: 'locationTypes[]',
7268
})
7369
@IsOptional()
7470
@IsEnum(LOCATION_TYPES, {
7571
each: true,
7672
message:
7773
'Available options: ' +
78-
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
74+
Object.values(LOCATION_TYPES).toString().toLowerCase(),
7975
})
80-
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
81-
transformLocationType(value),
82-
)
8376
@Type(() => String)
84-
locationTypes?: LOCATION_TYPES_PARAMS[];
77+
locationTypes?: LOCATION_TYPES[];
8578
}
8679

8780
export class GetImpactMapDto extends BaseGetImpactMapDto {

api/src/modules/h3-data/h3-data-map.repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from 'modules/h3-data/h3-data.entity';
1414
import { Logger, ServiceUnavailableException } from '@nestjs/common';
1515
import {
16-
LOCATION_TYPES_PARAMS,
16+
LOCATION_TYPES,
1717
SourcingLocation,
1818
} from 'modules/sourcing-locations/sourcing-location.entity';
1919
import { SourcingRecord } from 'modules/sourcing-records/sourcing-record.entity';
@@ -315,7 +315,7 @@ export class H3DataMapRepository extends Repository<H3Data> {
315315
materialIds?: string[],
316316
originIds?: string[],
317317
supplierIds?: string[],
318-
locationTypes?: LOCATION_TYPES_PARAMS[],
318+
locationTypes?: LOCATION_TYPES[],
319319
baseQueryExtend?: (baseQuery: SelectQueryBuilder<any>) => void,
320320
scenarioComparisonQuantiles?: boolean,
321321
): Promise<{ impactMap: H3IndexValueData[]; quantiles: number[] }> {

api/src/modules/impact/dto/impact-table.dto.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
1212
import { Transform, Type } from 'class-transformer';
1313

1414
import { GROUP_BY_VALUES } from 'modules/h3-data/dto/get-impact-map.dto';
15-
import {
16-
LOCATION_TYPES,
17-
LOCATION_TYPES_PARAMS,
18-
} from 'modules/sourcing-locations/sourcing-location.entity';
19-
import { transformLocationType } from 'utils/transform-location-type.util';
15+
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';
16+
import { replaceStringWhiteSpacesWithDash } from 'utils/transform-location-type.util';
2017

2118
export class BaseImpactTableDto {
2219
@ApiProperty({
@@ -71,21 +68,21 @@ export class BaseImpactTableDto {
7168

7269
@ApiPropertyOptional({
7370
description: 'Types of Sourcing Locations, written with hyphens',
74-
enum: Object.values(LOCATION_TYPES_PARAMS),
71+
enum: Object.values(LOCATION_TYPES),
7572
name: 'locationTypes[]',
7673
})
7774
@IsOptional()
7875
@IsEnum(LOCATION_TYPES, {
7976
each: true,
8077
message:
8178
'Available options: ' +
82-
Object.values(LOCATION_TYPES_PARAMS).toString().toLowerCase(),
79+
Object.values(LOCATION_TYPES).toString().toLowerCase(),
8380
})
84-
@Transform(({ value }: { value: LOCATION_TYPES_PARAMS[] }) =>
85-
transformLocationType(value),
81+
@Transform(({ value }: { value: LOCATION_TYPES[] }) =>
82+
replaceStringWhiteSpacesWithDash(value),
8683
)
8784
@Type(() => String)
88-
locationTypes?: LOCATION_TYPES_PARAMS[];
85+
locationTypes?: LOCATION_TYPES[];
8986
}
9087

9188
export class GetActualVsScenarioImpactTableDto extends BaseImpactTableDto {

api/src/modules/import-data/sourcing-data/dto-processor.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { SourcingDataExcelValidator } from 'modules/import-data/sourcing-data/va
1717
import { validateOrReject } from 'class-validator';
1818
import { plainToClass } from 'class-transformer';
1919
import { CreateIndicatorDto } from 'modules/indicators/dto/create.indicator.dto';
20+
import { replaceStringWhiteSpacesWithDash } from 'utils/transform-location-type.util';
21+
import { LOCATION_TYPES } from 'modules/sourcing-locations/sourcing-location.entity';
2022

2123
/**
2224
* @debt: Define a more accurate DTO / Interface / Class for API-DB trades
@@ -370,7 +372,9 @@ export class SourcingRecordsDtoProcessorService {
370372
): CreateSourcingLocationDto {
371373
const sourcingLocationDto: CreateSourcingLocationDto =
372374
new CreateSourcingLocationDto();
373-
sourcingLocationDto.locationType = sourcingLocationData.location_type;
375+
sourcingLocationDto.locationType = replaceStringWhiteSpacesWithDash(
376+
sourcingLocationData.location_type,
377+
) as LOCATION_TYPES;
374378
sourcingLocationDto.locationCountryInput =
375379
sourcingLocationData.location_country_input;
376380
sourcingLocationDto.locationAddressInput =

api/src/modules/import-data/sourcing-data/validators/address-input.custom.validator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class LocationAddressInputValidator
2020
return !addressInput;
2121
} else if (
2222
((args.object as SourcingDataExcelValidator).location_type ===
23-
LOCATION_TYPES.AGGREGATION_POINT ||
23+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
2424
(args.object as SourcingDataExcelValidator).location_type ===
2525
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
2626
((args.object as SourcingDataExcelValidator).location_latitude_input ||
@@ -29,7 +29,7 @@ export class LocationAddressInputValidator
2929
return !addressInput;
3030
} else if (
3131
((args.object as SourcingDataExcelValidator).location_type ===
32-
LOCATION_TYPES.AGGREGATION_POINT ||
32+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
3333
(args.object as SourcingDataExcelValidator).location_type ===
3434
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
3535
(!(args.object as SourcingDataExcelValidator).location_latitude_input ||
@@ -52,7 +52,7 @@ export class LocationAddressInputValidator
5252
}`;
5353
} else if (
5454
((args.object as SourcingDataExcelValidator).location_type ===
55-
LOCATION_TYPES.AGGREGATION_POINT ||
55+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
5656
(args.object as SourcingDataExcelValidator).location_type ===
5757
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
5858
((args.object as SourcingDataExcelValidator).location_latitude_input ||

api/src/modules/import-data/sourcing-data/validators/latitude-input.custom.validator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ export class LocationLatitudeInputValidator
2020
return !latitudeInput;
2121
} else if (
2222
((args.object as SourcingDataExcelValidator).location_type ===
23-
LOCATION_TYPES.AGGREGATION_POINT ||
23+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
2424
(args.object as SourcingDataExcelValidator).location_type ===
2525
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
2626
(args.object as SourcingDataExcelValidator).location_address_input
2727
) {
2828
return !latitudeInput;
2929
} else if (
3030
((args.object as SourcingDataExcelValidator).location_type ===
31-
LOCATION_TYPES.AGGREGATION_POINT ||
31+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
3232
(args.object as SourcingDataExcelValidator).location_type ===
3333
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
3434
!(args.object as SourcingDataExcelValidator).location_address_input
@@ -50,7 +50,7 @@ export class LocationLatitudeInputValidator
5050
}`;
5151
} else if (
5252
((args.object as SourcingDataExcelValidator).location_type ===
53-
LOCATION_TYPES.AGGREGATION_POINT ||
53+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
5454
(args.object as SourcingDataExcelValidator).location_type ===
5555
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
5656
(args.object as SourcingDataExcelValidator).location_address_input
@@ -60,7 +60,7 @@ export class LocationLatitudeInputValidator
6060
}. Latitude must be empty if address is provided`;
6161
} else if (
6262
(args.object as SourcingDataExcelValidator).location_type ===
63-
LOCATION_TYPES.AGGREGATION_POINT ||
63+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
6464
(args.object as SourcingDataExcelValidator).location_type ===
6565
LOCATION_TYPES.POINT_OF_PRODUCTION
6666
) {

api/src/modules/import-data/sourcing-data/validators/longitude-input.custom.validator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ export class LocationLongitudeInputValidator
2020
return !longitudeInput;
2121
} else if (
2222
((args.object as SourcingDataExcelValidator).location_type ===
23-
LOCATION_TYPES.AGGREGATION_POINT ||
23+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
2424
(args.object as SourcingDataExcelValidator).location_type ===
2525
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
2626
(args.object as SourcingDataExcelValidator).location_address_input
2727
) {
2828
return !longitudeInput;
2929
} else if (
3030
((args.object as SourcingDataExcelValidator).location_type ===
31-
LOCATION_TYPES.AGGREGATION_POINT ||
31+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
3232
(args.object as SourcingDataExcelValidator).location_type ===
3333
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
3434
!(args.object as SourcingDataExcelValidator).location_address_input
@@ -50,7 +50,7 @@ export class LocationLongitudeInputValidator
5050
}`;
5151
} else if (
5252
((args.object as SourcingDataExcelValidator).location_type ===
53-
LOCATION_TYPES.AGGREGATION_POINT ||
53+
LOCATION_TYPES.PRODUCTION_AGGREGATION_POINT ||
5454
(args.object as SourcingDataExcelValidator).location_type ===
5555
LOCATION_TYPES.POINT_OF_PRODUCTION) &&
5656
(args.object as SourcingDataExcelValidator).location_address_input

0 commit comments

Comments
 (0)