Skip to content

Commit

Permalink
feature(Specification): Moves the CSV Import event to the start of pr…
Browse files Browse the repository at this point in the history
…ocessing
  • Loading branch information
KevSanchez committed Apr 17, 2024
1 parent 3e92fe9 commit 7fb387b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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_feature_preparations_scenario_id__idx ON scenario_feature_preparations(scenario_id);
`);
}

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

0 comments on commit 7fb387b

Please sign in to comment.