diff --git a/api/src/modules/import-data/sourcing-data/sourcing-data-import.service.ts b/api/src/modules/import-data/sourcing-data/sourcing-data-import.service.ts index 92e1cf664..0fe60fa68 100644 --- a/api/src/modules/import-data/sourcing-data/sourcing-data-import.service.ts +++ b/api/src/modules/import-data/sourcing-data/sourcing-data-import.service.ts @@ -68,7 +68,7 @@ export class SourcingDataImportService { async importSourcingData(filePath: string, taskId: string): Promise { this.logger.log(`Starting import process`); - await this.fileService.isFilePresentInFs(filePath); + //await this.fileService.isFilePresentInFs(filePath); try { const parsedXLSXDataset: SourcingRecordsSheets = await this.fileService.transformToJson(filePath, SHEETS_MAP); @@ -77,80 +77,80 @@ export class SourcingDataImportService { await this.excelValidator.validate( parsedXLSXDataset as unknown as SourcingDataSheet, ); - if (validationErrors.length) { - throw new ExcelValidationError('Validation Errors', validationErrors); - } - - //TODO: Implement transactional import. Move geocoding to first step - - await this.dbCleaner.cleanDataBeforeImport(); - - const materials: Material[] = - await this.materialService.findAllUnpaginated(); - if (!materials.length) { - throw new ServiceUnavailableException( - 'No Materials found present in the DB. Please check the LandGriffon installation manual', - ); - } + // if (validationErrors.length) { + // throw new ExcelValidationError('Validation Errors', validationErrors); + // } + // + // //TODO: Implement transactional import. Move geocoding to first step + // + // await this.dbCleaner.cleanDataBeforeImport(); + // + // const materials: Material[] = + // await this.materialService.findAllUnpaginated(); + // if (!materials.length) { + // throw new ServiceUnavailableException( + // 'No Materials found present in the DB. Please check the LandGriffon installation manual', + // ); + // } this.logger.log('Activating Indicators...'); const activeIndicators: Indicator[] = await this.indicatorService.activateIndicators( dtoMatchedData.indicators, ); - this.logger.log('Activating Materials...'); - const activeMaterials: Material[] = - await this.materialService.activateMaterials(dtoMatchedData.materials); - - await this.tasksService.updateImportTask({ - taskId, - newLogs: [ - `Activated indicators: ${activeIndicators - .map((i: Indicator) => i.name) - .join(', ')}`, - `Activated materials: ${activeMaterials - .map((i: Material) => i.hsCodeId) - .join(', ')}`, - ], - }); - - const businessUnits: BusinessUnit[] = - await this.businessUnitService.createTree(dtoMatchedData.businessUnits); - - const suppliers: Supplier[] = await this.supplierService.createTree( - dtoMatchedData.suppliers, - ); - - const { geoCodedSourcingData, errors } = - await this.geoCodingService.geoCodeLocations( - dtoMatchedData.sourcingData, - ); - if (errors.length) { - throw new GeoCodingError( - 'Import failed. There are GeoCoding errors present in the file', - errors, - ); - } - const warnings: string[] = []; - geoCodedSourcingData.forEach((elem: SourcingData) => { - if (elem.locationWarning) warnings.push(elem.locationWarning); - }); - warnings.length > 0 && - (await this.tasksService.updateImportTask({ - taskId, - newLogs: warnings, - })); - - const sourcingDataWithOrganizationalEntities: SourcingLocation[] = - await this.relateSourcingDataWithOrganizationalEntities( - suppliers, - businessUnits, - materials, - geoCodedSourcingData, - ); - - await this.sourcingLocationService.save( - sourcingDataWithOrganizationalEntities, - ); + // this.logger.log('Activating Materials...'); + // const activeMaterials: Material[] = + // await this.materialService.activateMaterials(dtoMatchedData.materials); + // + // await this.tasksService.updateImportTask({ + // taskId, + // newLogs: [ + // `Activated indicators: ${activeIndicators + // .map((i: Indicator) => i.name) + // .join(', ')}`, + // `Activated materials: ${activeMaterials + // .map((i: Material) => i.hsCodeId) + // .join(', ')}`, + // ], + // }); + // + // const businessUnits: BusinessUnit[] = + // await this.businessUnitService.createTree(dtoMatchedData.businessUnits); + // + // const suppliers: Supplier[] = await this.supplierService.createTree( + // dtoMatchedData.suppliers, + // ); + // + // const { geoCodedSourcingData, errors } = + // await this.geoCodingService.geoCodeLocations( + // dtoMatchedData.sourcingData, + // ); + // if (errors.length) { + // throw new GeoCodingError( + // 'Import failed. There are GeoCoding errors present in the file', + // errors, + // ); + // } + // const warnings: string[] = []; + // geoCodedSourcingData.forEach((elem: SourcingData) => { + // if (elem.locationWarning) warnings.push(elem.locationWarning); + // }); + // warnings.length > 0 && + // (await this.tasksService.updateImportTask({ + // taskId, + // newLogs: warnings, + // })); + // + // const sourcingDataWithOrganizationalEntities: SourcingLocation[] = + // await this.relateSourcingDataWithOrganizationalEntities( + // suppliers, + // businessUnits, + // materials, + // geoCodedSourcingData, + // ); + // + // await this.sourcingLocationService.save( + // sourcingDataWithOrganizationalEntities, + // ); this.logger.log('Generating Indicator Records...'); diff --git a/api/src/modules/indicator-coefficients/indicator-coefficient.entity.ts b/api/src/modules/indicator-coefficients/indicator-coefficient.entity.ts index 017663e23..f1d05e4f6 100644 --- a/api/src/modules/indicator-coefficients/indicator-coefficient.entity.ts +++ b/api/src/modules/indicator-coefficients/indicator-coefficient.entity.ts @@ -2,6 +2,7 @@ import { BaseEntity, Column, Entity, + Index, ManyToOne, PrimaryGeneratedColumn, } from 'typeorm'; @@ -31,17 +32,20 @@ export class IndicatorCoefficient extends BaseEntity { @Column({ type: 'int' }) year!: number; + @Index() @ManyToOne(() => AdminRegion, (ar: AdminRegion) => ar.indicatorCoefficients, { nullable: true, }) adminRegion: AdminRegion; + @Index() @ManyToOne( () => Indicator, (indicator: Indicator) => indicator.indicatorCoefficients, ) indicator!: Indicator; + @Index() @ManyToOne(() => Material, (mat: Material) => mat.indicatorCoefficients) material!: Material; } diff --git a/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts b/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts index 7451abd0a..94fea813b 100644 --- a/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts +++ b/api/src/modules/indicator-records/services/impact-calculation.dependencies.ts @@ -138,7 +138,7 @@ export const INDICATOR_NAME_CODE_TO_QUERY_MAP: { }, [INDICATOR_NAME_CODES.WW]: { [INDICATOR_NAME_CODES.WW]: () => - `${get_indicator_coefficient_impact}('${INDICATOR_NAME_CODES.WW}', $3, $2) as "${INDICATOR_NAME_CODES.WU}"`, + `${get_indicator_coefficient_impact}('${INDICATOR_NAME_CODES.WW}', $3, $2) as "${INDICATOR_NAME_CODES.WW}"`, }, [INDICATOR_NAME_CODES.WC]: { [INDICATOR_NAME_CODES.WC]: () => diff --git a/api/src/modules/sourcing-locations/sourcing-location.entity.ts b/api/src/modules/sourcing-locations/sourcing-location.entity.ts index d8282832a..dac96dcba 100644 --- a/api/src/modules/sourcing-locations/sourcing-location.entity.ts +++ b/api/src/modules/sourcing-locations/sourcing-location.entity.ts @@ -2,6 +2,7 @@ import { Check, Column, Entity, + In, Index, JoinColumn, ManyToOne, @@ -136,6 +137,7 @@ export class SourcingLocation extends TimestampedBaseEntity { material: Material; @ApiPropertyOptional() + @Index('sourcing_location_material_id_index') @Column() materialId: string; @@ -147,6 +149,7 @@ export class SourcingLocation extends TimestampedBaseEntity { adminRegion: AdminRegion; @Column({ nullable: true }) + @Index('sourcing_location_admin_region_id_index') @ApiPropertyOptional() adminRegionId: string;