Skip to content

Commit

Permalink
fix(CostSurface): Fixes missing min/max update for default CostSurfac…
Browse files Browse the repository at this point in the history
…e metadata for non shapefile based Projects
  • Loading branch information
KevSanchez committed Nov 24, 2023
1 parent aca8a31 commit c9f1433
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 50 deletions.
3 changes: 2 additions & 1 deletion api/apps/api/src/modules/projects/projects-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ export class ProjectsCrudService extends AppBaseService<
this.logger.debug(
'creating planning unit job and assigning project to area',
);
const defaultCostSurfaceId = getDefaultCostSurfaceIdFromProject(model);
await Promise.all([
this.planningUnitsService.create({
...createModel,
planningUnitAreakm2: createModel.planningUnitAreakm2,
planningUnitGridShape: createModel.planningUnitGridShape,
projectId: model.id,
costSurfaceId: getDefaultCostSurfaceIdFromProject(model),
costSurfaceId: defaultCostSurfaceId,
}),
this.planningAreasService.assignProject({
projectId: model.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ import { ProjectCostSurfacePersistencePort } from '@marxan-geoprocessing/modules
useClass: ShapefileConverter,
},
],
exports: [ProjectCostSurfacePersistencePort],
})
export class ProjectCostSurfaceModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { validate } from 'class-validator';
import { chunk } from 'lodash';
import { EntityManager } from 'typeorm';
import { CHUNK_SIZE_FOR_BATCH_GEODB_OPERATIONS } from '@marxan-geoprocessing/utils/chunk-size-for-batch-geodb-operations';
import { ProjectCostSurfacePersistencePort } from '@marxan-geoprocessing/modules/cost-surface/ports/persistence/project-cost-surface-persistence.port';

type CustomPlanningAreaJob = Required<
export type CustomPlanningAreaJob = Required<
Omit<
PlanningUnitsJob,
'countryId' | 'adminRegionId' | 'adminAreaLevel1Id' | 'adminAreaLevel2Id'
Expand Down Expand Up @@ -56,6 +57,7 @@ export class PlanningUnitsJobProcessor {
private logger = new Logger('planning-units-job-processor');

constructor(
private readonly repo: ProjectCostSurfacePersistencePort,
@InjectEntityManager()
private readonly entityManager: EntityManager,
) {}
Expand Down Expand Up @@ -262,6 +264,8 @@ grid.geom

return geometries;
});

await this.repo.updateCostSurfaceRange(job.data.costSurfaceId!);
this.logger.debug(`Finished planning-units processing for ${job.id}`);
} catch (err) {
this.logger.error(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { ShapefileService, FileService } from '@marxan/shapefile-converter';
import { PlanningUnitsService } from './planning-units.service';
import { WorkerModule } from '../worker';
import { PlanningUnitsJobProcessor } from './planning-units.job';
import { ProjectCostSurfaceModule } from '@marxan-geoprocessing/modules/cost-surface/project/project-cost-surface.module';

@Module({
imports: [TileModule, WorkerModule],
imports: [TileModule, WorkerModule, ProjectCostSurfaceModule],
providers: [
PlanningUnitsProcessor,
ShapefileService,
Expand Down
31 changes: 23 additions & 8 deletions api/apps/geoprocessing/test/e2e.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import * as faker from 'faker';
import { PlanningUnitsJob } from '@marxan-jobs/planning-unit-geometry';
import { PlanningUnitGridShape } from '@marxan/scenarios-planning-unit';

interface OptionsWithCountryCode {
export interface OptionsWithCountryCode {
countryCode: string;
adminAreaLevel1Id?: string;
adminAreaLevel2Id?: string;
planningUnitAreakm2?: number;
projectId?: string;
costSurfaceId?: string;
}

export const E2E_CONFIG: {
Expand All @@ -32,16 +35,22 @@ export const E2E_CONFIG: {
adminAreaLevel2Id:
options.adminAreaLevel2Id ?? faker.random.alphaNumeric(12),
planningUnitGridShape: PlanningUnitGridShape.Hexagon,
planningUnitAreakm2: 100,
projectId: 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
planningUnitAreakm2: options.planningUnitAreakm2 ?? 100,
projectId:
options.projectId ?? 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
costSurfaceId:
options.costSurfaceId ?? '700d7cf9-011b-4adf-bbe8-4c35a100abc0',
}),
adminRegion: (options: OptionsWithCountryCode): PlanningUnitsJob => ({
countryId: options.countryCode,
adminAreaLevel1Id: faker.random.alphaNumeric(7),
adminAreaLevel2Id: faker.random.alphaNumeric(12),
planningUnitGridShape: PlanningUnitGridShape.Square,
planningUnitAreakm2: 100,
projectId: 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
planningUnitAreakm2: options.planningUnitAreakm2 ?? 100,
projectId:
options.projectId ?? 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
costSurfaceId:
options.costSurfaceId ?? '700d7cf9-011b-4adf-bbe8-4c35a100abc0',
}),
},
invalid: {
Expand All @@ -51,15 +60,21 @@ export const E2E_CONFIG: {
adminAreaLevel2Id: faker.random.alphaNumeric(12),
planningUnitGridShape: PlanningUnitGridShape.Hexagon,
planningUnitAreakm2: -100,
projectId: 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
projectId:
options.projectId ?? 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
costSurfaceId:
options.costSurfaceId ?? '700d7cf9-011b-4adf-bbe8-4c35a100abc0',
}),
adminRegion: (options: OptionsWithCountryCode): PlanningUnitsJob => ({
countryId: options.countryCode,
adminAreaLevel1Id: faker.random.alphaNumeric(7),
adminAreaLevel2Id: faker.random.alphaNumeric(12),
planningUnitGridShape: PlanningUnitGridShape.Square,
planningUnitAreakm2: 100,
projectId: 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
planningUnitAreakm2: options.planningUnitAreakm2 ?? 100,
projectId:
options.projectId ?? 'a9d965a2-35ce-44b2-8112-50bcdfe98447',
costSurfaceId:
options.costSurfaceId ?? '700d7cf9-011b-4adf-bbe8-4c35a100abc0',
}),
},
},
Expand Down
Loading

0 comments on commit c9f1433

Please sign in to comment.