From 2a8a2eef62efaad50c7d449488d9308f78162b72 Mon Sep 17 00:00:00 2001 From: Ruben Vallejo Date: Tue, 29 Mar 2022 18:48:24 +0200 Subject: [PATCH] feat: adds new columns and method for blmFinalResults entity and repo --- .../blm-final-results.repository.ts | 26 +++++++++++++++++-- ...rotectedPUIdsPngColumnToBlmFinalResults.ts | 4 +-- .../src/blm-final-results.geo.entity.ts | 13 ++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/api/apps/geoprocessing/src/marxan-sandboxed-runner/adapters-blm/blm-final-results.repository.ts b/api/apps/geoprocessing/src/marxan-sandboxed-runner/adapters-blm/blm-final-results.repository.ts index 13383c131c..71c83c31ee 100644 --- a/api/apps/geoprocessing/src/marxan-sandboxed-runner/adapters-blm/blm-final-results.repository.ts +++ b/api/apps/geoprocessing/src/marxan-sandboxed-runner/adapters-blm/blm-final-results.repository.ts @@ -29,8 +29,8 @@ export class BlmFinalResultsRepository { }); const query = ` - insert into blm_final_results (scenario_id, blm_value, cost, boundary_length) - select scenario_id, blm_value, cost, boundary_length from blm_partial_results + insert into blm_final_results (scenario_id, blm_value, cost, boundary_length, protected_pu_ids) + select scenario_id, blm_value, cost, boundary_length, protected_pu_ids from blm_partial_results where blm_partial_results.scenario_id = $1 and blm_partial_results.calibration_id = $2 `; @@ -40,4 +40,26 @@ export class BlmFinalResultsRepository { return Promise.resolve(undefined); } + + async updatePngDataOnFinalResults( + scenarioId: string, + pngData: string, + ): Promise { + await this.entityManager.transaction(async (txManager) => { + const query = ` + update blm_final_results + set protected_pu_ids NULL + where blm_final_results.scenario_id = $1`; + await txManager.query(query, [scenarioId]); + + const pngDataParsedBuffer = Buffer.from( + '\\x' + Buffer.from(pngData, 'base64').toString('hex'), + ); + await txManager.update( + BlmFinalResultEntity, + { scenarioId }, + { pngData: pngDataParsedBuffer }, + ); + }); + } } diff --git a/api/apps/geoprocessing/src/migrations/geoprocessing/1648559688744-AddProtectedPUIdsPngColumnToBlmFinalResults.ts b/api/apps/geoprocessing/src/migrations/geoprocessing/1648559688744-AddProtectedPUIdsPngColumnToBlmFinalResults.ts index 5654f6594c..d298ed3d6d 100644 --- a/api/apps/geoprocessing/src/migrations/geoprocessing/1648559688744-AddProtectedPUIdsPngColumnToBlmFinalResults.ts +++ b/api/apps/geoprocessing/src/migrations/geoprocessing/1648559688744-AddProtectedPUIdsPngColumnToBlmFinalResults.ts @@ -5,7 +5,7 @@ export class AddProtectedPUIdsPngColumnToBlmFinalResults1648570380744 public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(` ALTER TABLE blm_final_results - ADD COLUMN protected_pu_ids uuid[] + ADD COLUMN protected_pu_ids uuid[], ADD COLUMN png_data bytea; `); } @@ -13,7 +13,7 @@ export class AddProtectedPUIdsPngColumnToBlmFinalResults1648570380744 public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(` ALTER TABLE blm_partial_results - DROP COLUMN protected_pu_ids + DROP COLUMN protected_pu_ids, DROP COLUMN png_data; `); } diff --git a/api/libs/blm-calibration/src/blm-final-results.geo.entity.ts b/api/libs/blm-calibration/src/blm-final-results.geo.entity.ts index f8e14d7a0e..2c9ade7e28 100644 --- a/api/libs/blm-calibration/src/blm-final-results.geo.entity.ts +++ b/api/libs/blm-calibration/src/blm-final-results.geo.entity.ts @@ -42,4 +42,17 @@ export class BlmFinalResultEntity { type: 'float', }) boundaryLength!: number; + + @Column({ + name: `protected_pu_ids`, + type: 'uuid', + array: true, + }) + protected_pu_ids!: string[]; + + @Column({ + name: `png_data`, + type: 'bytea', + }) + pngData!: Buffer; }