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

emit correct api events when dealing with cost surface uploads [MRXN23-472] #1576

Merged
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
@@ -1,4 +1,3 @@

import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddTokenIdColumnToLocks1645026803969
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class SyncPuShapeEnumFromGeoprocessingToApi1645449750000
implements MigrationInterface {
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TYPE planning_unit_grid_shape ADD VALUE 'irregular';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddCostSurfaceLinkingNewEvents1696603545456
implements MigrationInterface {
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
INSERT INTO api_event_kinds (id) values
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddMinMaxAmountColumnsToFeatures1697210673344 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
export class AddMinMaxAmountColumnsToFeatures1697210673344
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE features
ADD COLUMN amount_min float8,
ADD COLUMN amount_max float8;
`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE features
DROP COLUMN amount_min float8,
DROP COLUMN amount_max float8;
`);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
@Injectable()
export class ScenarioCostSurfaceApiEvents
extends ApiEventsService
implements ScenarioCostSurfaceEventsPort {
implements ScenarioCostSurfaceEventsPort
{
private readonly eventsMap: Record<
ScenarioCostSurfaceState,
API_EVENT_KINDS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { scenarioCostSurfaceQueueToken } from '@marxan-api/modules/cost-surface/

@CommandHandler(LinkCostSurfaceToScenarioCommand)
export class LinkCostSurfaceToScenarioHandler
implements IInferredCommandHandler<LinkCostSurfaceToScenarioCommand> {
implements IInferredCommandHandler<LinkCostSurfaceToScenarioCommand>
{
private readonly logger: Logger = new Logger(
LinkCostSurfaceToScenarioHandler.name,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ export class ProjectCostSurfaceEventsHandler
{
private queueEvents: QueueEventsAdapter<ProjectCostSurfaceJobInput, true>;

// TODO!!! Create proper events

private failEventsMapper: EventKind = {
event: API_EVENT_KINDS.scenario__costSurface__costUpdateFailed__v1_alpha1,
event: API_EVENT_KINDS.project__costSurface_shapefile_failed__v1alpha1,
};

private successEventsMapper: EventKind = {
event: API_EVENT_KINDS.scenario__costSurface__finished__v1_alpha1,
event: API_EVENT_KINDS.project__costSurface_shapefile_finished__v1alpha1,
};

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type EventKind = { event: API_EVENT_KINDS };

@Injectable()
export class ScenarioCostSurfaceEventsHandler
implements EventFactory<ScenarioCostSurfaceJobInput, true> {
implements EventFactory<ScenarioCostSurfaceJobInput, true>
{
private queueEvents: QueueEventsAdapter<ScenarioCostSurfaceJobInput, true>;

private failEventsMapper: EventKind = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ export const scenarioCostSurfaceQueueProvider: FactoryProvider<
},
inject: [QueueBuilder],
};
export const scenarioCostSurfaceQueueEventsProvider: FactoryProvider<QueueEvents> = {
provide: scenarioCostSurfaceEventsToken,
useFactory: (eventsBuilder: QueueEventsBuilder) => {
return eventsBuilder.buildQueueEvents(scenarioCostSurfaceQueueName);
},
inject: [QueueEventsBuilder],
};
export const scenarioCostSurfaceQueueEventsProvider: FactoryProvider<QueueEvents> =
{
provide: scenarioCostSurfaceEventsToken,
useFactory: (eventsBuilder: QueueEventsBuilder) => {
return eventsBuilder.buildQueueEvents(scenarioCostSurfaceQueueName);
},
inject: [QueueEventsBuilder],
};

export const scenarioCostSurfaceEventsFactoryProvider: FactoryProvider<
CreateWithEventFactory<ScenarioCostSurfaceJobInput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ export class GeoFeaturesController {
async findAll(
@ProcessFetchSpecification() fetchSpecification: FetchSpecification,
): Promise<GeoFeatureResult> {
const results = await this.geoFeatureService.findAllPaginated(
fetchSpecification,
);
const results =
await this.geoFeatureService.findAllPaginated(fetchSpecification);
return this.geoFeatureService.serialize(results.data, results.metadata);
}

Expand Down
19 changes: 10 additions & 9 deletions api/apps/api/src/modules/planning-areas/planning-areas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ export class PlanningAreasService {
private readonly allPlanningAreaService: AllPlanningAreasService,
) {}

savePlanningAreaFromShapefile = this.uploader.savePlanningAreaFromShapefile.bind(
this.uploader,
);
savePlanningAreaFromShapefile =
this.uploader.savePlanningAreaFromShapefile.bind(this.uploader);

locatePlanningAreaEntity = this.allPlanningAreaService.locatePlanningAreaEntity.bind(
this.allPlanningAreaService,
);
locatePlanningAreaEntity =
this.allPlanningAreaService.locatePlanningAreaEntity.bind(
this.allPlanningAreaService,
);

getPlanningAreaIdAndName = this.allPlanningAreaService.getPlanningAreaIdAndName.bind(
this.allPlanningAreaService,
);
getPlanningAreaIdAndName =
this.allPlanningAreaService.getPlanningAreaIdAndName.bind(
this.allPlanningAreaService,
);

getPlanningAreaBBox = this.allPlanningAreaService.getPlanningAreaBBox.bind(
this.allPlanningAreaService,
Expand Down
14 changes: 7 additions & 7 deletions api/apps/api/src/modules/projects/projects-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const projectFilterKeyNames = [
] as const;
type ProjectFilterKeys = keyof Pick<
Project,
typeof projectFilterKeyNames[number]
(typeof projectFilterKeyNames)[number]
>;
type ProjectFilters = Record<ProjectFilterKeys, string[]>;

Expand Down Expand Up @@ -241,9 +241,8 @@ export class ProjectsCrudService extends AppBaseService<
_info?: ProjectsRequest,
): Promise<Project> {
const ids: MultiplePlanningAreaIds = entity;
const idAndName = await this.planningAreasService.getPlanningAreaIdAndName(
ids,
);
const idAndName =
await this.planningAreasService.getPlanningAreaIdAndName(ids);
if (isDefined(idAndName)) {
entity.planningAreaId = idAndName.planningAreaId;
entity.planningAreaName = idAndName.planningAreaName;
Expand Down Expand Up @@ -361,7 +360,8 @@ export class ProjectsCrudService extends AppBaseService<
return [await Promise.all(extendedEntities), entitiesAndCount[1]];
}

locatePlanningAreaEntity = this.planningAreasService.locatePlanningAreaEntity.bind(
this.planningAreasService,
);
locatePlanningAreaEntity =
this.planningAreasService.locatePlanningAreaEntity.bind(
this.planningAreasService,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ export class ProjectFeaturesController {
throw new BadRequestException(`Only FeatureCollection is supported.`);
}

const newFeatureOrError = await this.geoFeatureService.createFeaturesForShapefile(
projectId,
body,
data.features,
);
const newFeatureOrError =
await this.geoFeatureService.createFeaturesForShapefile(
projectId,
body,
data.features,
);

if (isLeft(newFeatureOrError)) {
// @debt Use mapDomainToHttpException() instead
Expand Down Expand Up @@ -480,11 +481,12 @@ export class ProjectFeaturesController {
@Param('projectId', ParseUUIDPipe) projectId: string,
@Param('featureId', ParseUUIDPipe) featureId: string,
): Promise<void> {
const checkCostSurfaceForProject = await this.geoFeatureService.checkProjectFeatureVisibility(
req.user.id,
projectId,
featureId,
);
const checkCostSurfaceForProject =
await this.geoFeatureService.checkProjectFeatureVisibility(
req.user.id,
projectId,
featureId,
);
if (isLeft(checkCostSurfaceForProject)) {
throw mapAclDomainToHttpError(checkCostSurfaceForProject.left);
}
Expand Down
8 changes: 2 additions & 6 deletions api/apps/api/src/modules/scenarios/scenarios.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ import {
} from '@marxan-api/modules/blm/values/blm-repos';

import { ExportScenario } from '../clone/export/application/export-scenario.command';
import {
SetInitialCostSurfaceError,
} from '@marxan-api/modules/cost-surface/application/set-initial-cost-surface.command';
import { SetInitialCostSurfaceError } from '@marxan-api/modules/cost-surface/application/set-initial-cost-surface.command';
import { UpdateCostSurface } from '@marxan-api/modules/cost-surface/application/update-cost-surface.command';
import { DeleteScenario } from '@marxan-api/modules/cost-surface/infra/delete-scenario.command';
import {
Expand Down Expand Up @@ -121,9 +119,7 @@ import { lastValueFrom } from 'rxjs';
import { AdjustPlanningUnitsInput } from '@marxan-api/modules/analysis/entry-points/adjust-planning-units-input';
import { submissionFailed } from '@marxan-api/modules/projects/protected-area/add-protected-area.service';
import { CostSurface } from '@marxan-api/modules/cost-surface/cost-surface.api.entity';
import {
costSurfaceNotFound,
} from '@marxan-api/modules/cost-surface/cost-surface.service';
import { costSurfaceNotFound } from '@marxan-api/modules/cost-surface/cost-surface.service';
import {
LinkCostSurfaceToScenarioCommand,
linkCostSurfaceToScenarioFailed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ describe('Get Project Cost Surface', () => {
await fixtures.GivenScenario(projectId, costSurface2.id);
await fixtures.GivenScenario(projectId, costSurface2.id);
// ACT
const response = await fixtures.WhenGettingCostSurfacesForProject(
projectId,
);
const response =
await fixtures.WhenGettingCostSurfacesForProject(projectId);

// ASSERT
await fixtures.ThenProjectNotViewableErrorWasReturned(response);
Expand Down Expand Up @@ -89,9 +88,8 @@ describe('Link Cost Surface To Scenario', () => {
it(`should not update CostSurface API entity if the user doesn't have permissions to edit the project`, async () => {
// ARRANGE
const projectId = await fixtures.GivenProject('someProject');
const defaultCostSurface = await fixtures.GivenDefaultCostSurfaceForProject(
projectId,
);
const defaultCostSurface =
await fixtures.GivenDefaultCostSurfaceForProject(projectId);
const costSurface = await fixtures.GivenCostSurfaceMetadataForProject(
projectId,
'someName',
Expand Down
Loading