From 5b7f2ce8df3d8e6a395ae0d9d14f5e99aeba594e Mon Sep 17 00:00:00 2001 From: andrea rota Date: Fri, 19 Apr 2024 19:58:55 +0100 Subject: [PATCH] only insert into fappu table once all the features_data rows have been created, to avoid inserting duplicates [MRXN23-609] --- .../import/features-amounts-upload.service.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts b/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts index 8bebca9f9a..19e49e730f 100644 --- a/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts +++ b/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts @@ -398,12 +398,6 @@ export class FeatureAmountUploadService { `, parameters, ); - await geoQueryRunner.manager.query( - ` INSERT INTO feature_amounts_per_planning_unit (project_id, feature_id, amount, project_pu_id) - SELECT $1, $2, amount, project_pu_id - FROM features_data where feature_id = $2`, - [projectId, newFeature.id], - ); this.logger.log( `Chunk ${amountIndex}/${featuresChunks.length} saved to (geoDB).features_data`, ); @@ -411,6 +405,13 @@ export class FeatureAmountUploadService { this.logger.log( `All chunks of feature ${newFeature.feature_class_name} saved`, ); + + await geoQueryRunner.manager.query( + `INSERT INTO feature_amounts_per_planning_unit (project_id, feature_id, amount, project_pu_id) + SELECT $1, $2, amount, project_pu_id + FROM features_data where feature_id = $2`, + [projectId, newFeature.id], + ); } this.logger.log( `Data for all new features was saved to (geoDB).features_data`,