Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRXN23-619] Delete previous ScenarioFeaturePreparation rows before processing a Specificaiton #1680

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import { SpecificationFeatureConfigApiEntity } from './specification-feature-con
import { SpecificationCandidateCreatedHandler } from './specification-candidate-created.handler';

import { SpecificationRepository } from '../application/specification.repository';
import { ScenarioFeaturesPreparation } from '@marxan/features';
import { DbConnections } from '@marxan-api/ormconfig.connections';

@Module({
imports: [
TypeOrmModule.forFeature([
SpecificationApiEntity,
SpecificationFeatureConfigApiEntity,
]),
TypeOrmModule.forFeature(
[ScenarioFeaturesPreparation],
DbConnections.geoprocessingDB,
),
ApiEventsModule,
],
providers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { SpecificationCandidateCreated } from '../domain';
import { API_EVENT_KINDS } from '@marxan/api-events';
import { ApiEventsService } from '@marxan-api/modules/api-events/api-events.service';
import { InjectEntityManager } from '@nestjs/typeorm';
import { DbConnections } from '@marxan-api/ormconfig.connections';
import { EntityManager } from 'typeorm';
import { ScenarioFeaturesPreparation } from '@marxan/features';

@EventsHandler(SpecificationCandidateCreated)
export class SpecificationCandidateCreatedHandler
implements IEventHandler<SpecificationCandidateCreated>
{
constructor(private readonly apiEvents: ApiEventsService) {}
constructor(
private readonly apiEvents: ApiEventsService,
@InjectEntityManager(DbConnections.geoprocessingDB)
private readonly geoEntityManager: EntityManager,
) {}

async handle(event: SpecificationCandidateCreated) {
if (event.draft) return;

await this.geoEntityManager.delete(ScenarioFeaturesPreparation, {
scenarioId: event.scenarioId,
});

await this.apiEvents.create({
kind: API_EVENT_KINDS.scenario__specification__submitted__v1__alpha1,
topic: event.scenarioId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddScenarioIndexForScenarioFeaturePreparation1713363912361
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE INDEX scenario_features_preparation_scenario_id__idx ON scenario_features_preparation(scenario_id);
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX scenario_features_preparation_scenario_id__idx;`,
);
}
}
Loading