-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): keep only current specification data in the table for proce…
…ssing
- Loading branch information
Showing
22 changed files
with
350 additions
and
167 deletions.
There are no files selected for viewing
23 changes: 6 additions & 17 deletions
23
api/apps/api/src/modules/scenario-specification/adapters/specification-activated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...pi/src/modules/scenario-specification/adapters/specification-processing-finished.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IEvent } from '@nestjs/cqrs'; | ||
|
||
export class SpecificationProcessingFinishedEvent implements IEvent { | ||
constructor( | ||
public readonly scenarioId: string, | ||
public readonly specificationId: string, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { ScenarioSpecificationModule } from './scenario-specification.module'; | ||
export { SpecificationActivated } from './domain'; | ||
export { SpecificationProcessingFinishedEvent } from './adapters/specification-processing-finished.event'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
api/apps/api/src/modules/scenarios-features/move-data-from-preparation.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Command } from '@nestjs-architects/typed-cqrs'; | ||
|
||
export class MoveDataFromPreparationCommand extends Command<void> { | ||
constructor( | ||
public readonly scenarioId: string, | ||
public readonly specificationId: string, | ||
) { | ||
super(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
api/apps/api/src/modules/scenarios-features/move-data-from-preparation.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
CommandHandler, | ||
EventBus, | ||
IInferredCommandHandler, | ||
} from '@nestjs/cqrs'; | ||
import { EntityManager } from 'typeorm'; | ||
import { InjectEntityManager } from '@nestjs/typeorm'; | ||
import { | ||
ScenarioFeaturesPreparation, | ||
ScenarioFeaturesData, | ||
} from '@marxan/features'; | ||
import { DbConnections } from '@marxan-api/ormconfig.connections'; | ||
import { SpecificationProcessingFinishedEvent } from '@marxan-api/modules/scenario-specification'; | ||
import { MoveDataFromPreparationCommand } from './move-data-from-preparation.command'; | ||
|
||
@CommandHandler(MoveDataFromPreparationCommand) | ||
export class MoveDataFromPreparationHandler | ||
implements IInferredCommandHandler<MoveDataFromPreparationCommand> { | ||
constructor( | ||
@InjectEntityManager(DbConnections.geoprocessingDB) | ||
private readonly entityManager: EntityManager, | ||
private readonly eventBus: EventBus, | ||
) {} | ||
|
||
async execute(command: MoveDataFromPreparationCommand): Promise<void> { | ||
await this.entityManager.transaction(async (transactionalEntityManager) => { | ||
await transactionalEntityManager.delete(ScenarioFeaturesData, { | ||
scenarioId: command.scenarioId, | ||
}); | ||
await transactionalEntityManager.query( | ||
` | ||
insert into scenario_features_data as sfd (id, | ||
feature_class_id, | ||
scenario_id, | ||
total_area, | ||
current_pa, | ||
fpf, | ||
target, | ||
prop, | ||
target2, | ||
targetocc, | ||
sepnum, | ||
created_by, | ||
metadata, | ||
specification_id) | ||
select id, | ||
feature_class_id, | ||
scenario_id, | ||
total_area, | ||
current_pa, | ||
fpf, | ||
target, | ||
prop, | ||
target2, | ||
targetocc, | ||
sepnum, | ||
created_by, | ||
metadata, | ||
specification_id | ||
from scenario_features_preparation sfp | ||
where sfp.specification_id = $1 | ||
`, | ||
[command.specificationId], | ||
); | ||
await transactionalEntityManager.delete(ScenarioFeaturesPreparation, { | ||
specificationId: command.specificationId, | ||
}); | ||
}); | ||
|
||
this.eventBus.publish( | ||
new SpecificationProcessingFinishedEvent( | ||
command.scenarioId, | ||
command.specificationId, | ||
), | ||
); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
api/apps/api/src/modules/scenarios-features/move-data-from-preparation.saga.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ICommand, ofType, Saga } from '@nestjs/cqrs'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { SpecificationActivated } from '@marxan-api/modules/scenario-specification'; | ||
import { MoveDataFromPreparationCommand } from './move-data-from-preparation.command'; | ||
|
||
@Injectable() | ||
export class MoveDataFromPreparationSaga { | ||
@Saga() | ||
specificationActivated = (events$: Observable<any>): Observable<ICommand> => { | ||
return events$.pipe( | ||
ofType(SpecificationActivated), | ||
map( | ||
(event) => | ||
new MoveDataFromPreparationCommand( | ||
event.scenarioId, | ||
event.specificationId.value, | ||
), | ||
), | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ng/src/migrations/geoprocessing/1629831194337-AddSpecificationIdToScenarioFeaturesData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddSpecificationIdToScenarioFeaturesData1629831194337 | ||
implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE scenario_features_data ADD COLUMN specification_id uuid`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE scenario_features_data DROP COLUMN specification_id; | ||
`); | ||
} | ||
} |
Oops, something went wrong.