Skip to content

Commit

Permalink
feat: adds new columns and method for blmFinalResults entity and repo
Browse files Browse the repository at this point in the history
  • Loading branch information
rubvalave committed Mar 30, 2022
1 parent a592d08 commit 5212f16
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;

Expand All @@ -40,4 +40,26 @@ export class BlmFinalResultsRepository {

return Promise.resolve(undefined);
}

async updatePngDataOnFinalResults(
scenarioId: string,
pngData: string,
): Promise<void> {
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 },
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export class AddProtectedPUIdsPngColumnToBlmFinalResults1648570380744
public async up(queryRunner: QueryRunner): Promise<void> {
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;
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE blm_partial_results
DROP COLUMN protected_pu_ids
DROP COLUMN protected_pu_ids,
DROP COLUMN png_data;
`);
}
Expand Down
13 changes: 13 additions & 0 deletions api/libs/blm-calibration/src/blm-final-results.geo.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 5212f16

Please sign in to comment.