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

refactor: create library for scenario planning units #221

Merged
merged 3 commits into from
Jun 1, 2021
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,5 +1,7 @@
import { ScenariosPlanningUnitGeoEntity } from '../../../../scenarios-planning-unit/entities/scenarios-planning-unit.geo.entity';
import { LockStatus } from '../../../../scenarios-planning-unit/lock-status.enum';
import {
LockStatus,
ScenariosPlanningUnitGeoEntity,
} from '@marxan/scenarios-planning-unit';
import { v4 } from 'uuid';

export const validDataWithGivenPuIds = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { ArePuidsAllowedAdapter } from './are-puids-allowed-adapter';
import { Test } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';

import { remoteConnectionName } from '../../../../scenarios-features/entities/remote-connection-name';
import { ScenariosPlanningUnitGeoEntity } from '../../../../scenarios-planning-unit/entities/scenarios-planning-unit.geo.entity';
import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';

import { fakeQueryBuilder } from '../../../../../utils/__mocks__/fake-query-builder';
import { validDataWithGivenPuIds } from '../__mocks__/scenario-planning-unit-geo.data';
import { DbConnections } from '@marxan-api/ormconfig.connections';

const existingPuids = ['one', 'two', 'three'];
const scenarioId = 'scenario-0000-fake-uuid';
Expand All @@ -16,7 +16,7 @@ let sut: ArePuidsAllowedAdapter;
beforeEach(async () => {
const geoRepoToken = getRepositoryToken(
ScenariosPlanningUnitGeoEntity,
remoteConnectionName,
DbConnections.geoprocessingDB,
);
const sandbox = await Test.createTestingModule({
providers: [
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { remoteConnectionName } from './entities/remote-connection-name';
import { ScenariosPlanningUnitGeoEntity } from './entities/scenarios-planning-unit.geo.entity';
import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';
import { DbConnections } from '@marxan-api/ormconfig.connections';
import { ScenariosPlanningUnitService } from './scenarios-planning-unit.service';

@Module({
imports: [
TypeOrmModule.forFeature(
[ScenariosPlanningUnitGeoEntity],
remoteConnectionName,
DbConnections.geoprocessingDB,
),
],
providers: [ScenariosPlanningUnitService],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, SelectQueryBuilder } from 'typeorm';
import { FiltersSpecification } from 'nestjs-base-service';

import { DbConnections } from '@marxan-api/ormconfig.connections';

import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';
import {
AppBaseService,
JSONAPISerializerConfig,
} from '../../utils/app-base.service';
import { AppConfig } from '../../utils/config.utils';
import { remoteConnectionName } from './entities/remote-connection-name';
import { ScenariosPlanningUnitGeoEntity } from './entities/scenarios-planning-unit.geo.entity';
import { UserSearchCriteria } from './search-criteria';
import { FiltersSpecification } from 'nestjs-base-service';

@Injectable()
export class ScenariosPlanningUnitService extends AppBaseService<
Expand All @@ -20,7 +21,10 @@ export class ScenariosPlanningUnitService extends AppBaseService<
UserSearchCriteria
> {
constructor(
@InjectRepository(ScenariosPlanningUnitGeoEntity, remoteConnectionName)
@InjectRepository(
ScenariosPlanningUnitGeoEntity,
DbConnections.geoprocessingDB,
)
private readonly puData: Repository<ScenariosPlanningUnitGeoEntity>,
) {
super(puData, 'scenario_planning_unit', 'scenario_planning_units', {
Expand Down
4 changes: 3 additions & 1 deletion api/apps/api/test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"moduleNameMapper": {
"@marxan-api/(.*)": "<rootDir>/../src/$1",
"^@marxan/utils": ["<rootDir>/../../../libs/utils/src"],
"^@marxan/utils/(.*)$": ["<rootDir>/../../..//libs/utils/src/$1"]
"^@marxan/utils/(.*)$": ["<rootDir>/../../..//libs/utils/src/$1"],
"^@marxan/scenarios-planning-unit": ["<rootDir>/../../../libs/scenarios-planning-unit/src"],
"^@marxan/scenarios-planning-unit/(.*)$": ["<rootDir>/../../../libs/scenarios-planning-unit/src/$1"]
}
}
9 changes: 6 additions & 3 deletions api/apps/api/test/scenario-pu-change/steps/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { v4 } from 'uuid';

import { GivenScenarioPuDataExists } from '../../steps/given-scenario-pu-data-exists';
import { ScenariosPlanningUnitGeoEntity } from '../../../src/modules/scenarios-planning-unit/entities/scenarios-planning-unit.geo.entity';
import { remoteConnectionName } from '../../../src/modules/scenarios-planning-unit/entities/remote-connection-name';
import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';

import { WhenChangingPlanningUnitInclusivity } from './WhenChangingPlanningUnitInclusivity';
import { DbConnections } from '@marxan-api/ormconfig.connections';

export interface World {
scenarioId: string;
Expand All @@ -24,7 +24,10 @@ export interface World {
export const createWorld = async (app: INestApplication): Promise<World> => {
const scenarioId = v4();
const scenariosPuData: Repository<ScenariosPlanningUnitGeoEntity> = await app.get(
getRepositoryToken(ScenariosPlanningUnitGeoEntity, remoteConnectionName),
getRepositoryToken(
ScenariosPlanningUnitGeoEntity,
DbConnections.geoprocessingDB,
),
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INestApplication } from '@nestjs/common';
import { bootstrapApplication } from '../utils/api-application';

import { ScenariosPlanningUnitService } from '../../src/modules/scenarios-planning-unit/scenarios-planning-unit.service';
import { LockStatus } from '../../src/modules/scenarios-planning-unit/lock-status.enum';
import { LockStatus } from '@marxan/scenarios-planning-unit';
import { createWorld, World } from './steps/world';
import { tearDown } from '../utils/tear-down';

Expand Down
9 changes: 6 additions & 3 deletions api/apps/api/test/scenarios-pu-data/steps/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { v4 } from 'uuid';

import { GivenScenarioPuDataExists } from '../../steps/given-scenario-pu-data-exists';
import { ScenariosPlanningUnitGeoEntity } from '../../../src/modules/scenarios-planning-unit/entities/scenarios-planning-unit.geo.entity';
import { remoteConnectionName } from '../../../src/modules/scenarios-planning-unit/entities/remote-connection-name';
import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';
import { DbConnections } from '@marxan-api/ormconfig.connections';

export interface World {
scenarioId: string;
Expand All @@ -16,7 +16,10 @@ export interface World {
export const createWorld = async (app: INestApplication): Promise<World> => {
const scenarioId = v4();
const scenariosPuData: Repository<ScenariosPlanningUnitGeoEntity> = await app.get(
getRepositoryToken(ScenariosPlanningUnitGeoEntity, remoteConnectionName),
getRepositoryToken(
ScenariosPlanningUnitGeoEntity,
DbConnections.geoprocessingDB,
),
);

return {
Expand Down
6 changes: 4 additions & 2 deletions api/apps/api/test/steps/given-scenario-pu-data-exists.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Repository } from 'typeorm';
import { v4 } from 'uuid';

import { ScenariosPlanningUnitGeoEntity } from '../../src/modules/scenarios-planning-unit/entities/scenarios-planning-unit.geo.entity';
import { LockStatus } from '../../src/modules/scenarios-planning-unit/lock-status.enum';
import {
LockStatus,
ScenariosPlanningUnitGeoEntity,
} from '@marxan/scenarios-planning-unit';

export const GivenScenarioPuDataExists = async (
repo: Repository<ScenariosPlanningUnitGeoEntity>,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
PrimaryGeneratedColumn,
RelationId,
} from 'typeorm';
import { ScenariosPlanningUnitGeoEntity } from './scenarios-planning-unit.geo.entity';
import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';

@Entity({
name: 'scenarios_pu_cost_data',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WorkerProcessor,
} from '@marxan-geoprocessing/modules/worker';
import { ShapefilesModule } from '@marxan-geoprocessing/modules/shapefiles/shapefiles.module';
import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';

import { SurfaceCostProcessor } from './application/surface-cost-processor';
import { SurfaceCostWorker } from './application/surface-cost-worker';
Expand All @@ -18,7 +19,6 @@ import { ShapefileConverterPort } from './ports/shapefile-converter/shapefile-co
import { TypeormCostSurface } from './adapters/typeorm-cost-surface';
import { ShapefileConverter } from './adapters/shapefile-converter';
import { ScenariosPuCostDataGeo } from '../scenarios/scenarios-pu-cost-data.geo.entity';
import { ScenariosPlanningUnitGeoEntity } from '../scenarios/scenarios-planning-unit.geo.entity';
import { PuCostExtractor } from './adapters/pu-cost-extractor';

@Module({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { v4 } from 'uuid';

import { ScenariosPlanningUnitGeoEntity } from '../../../src/modules/scenarios/scenarios-planning-unit.geo.entity';
import { ScenariosPlanningUnitGeoEntity } from '@marxan/scenarios-planning-unit';
import { GivenScenarioPuDataExists } from '../../steps/given-scenario-pu-data-exists';
import { ScenariosPuCostDataGeo } from '../../../src/modules/scenarios/scenarios-pu-cost-data.geo.entity';

Expand Down
4 changes: 3 additions & 1 deletion api/apps/geoprocessing/test/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"moduleNameMapper": {
"@marxan-geoprocessing/(.*)": "<rootDir>/src/$1",
"^@marxan/utils": ["<rootDir>/../../libs/utils/src"],
"^@marxan/utils/(.*)$": ["<rootDir>/../..//libs/utils/src/$1"]
"^@marxan/utils/(.*)$": ["<rootDir>/../..//libs/utils/src/$1"],
"^@marxan/scenarios-planning-unit": ["<rootDir>/../../libs/scenarios-planning-unit/src"],
"^@marxan/scenarios-planning-unit/(.*)$": ["<rootDir>/../../libs/scenarios-planning-unit/src/$1"]
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Repository } from 'typeorm';
import { v4 } from 'uuid';
import { ScenariosPlanningUnitGeoEntity } from '../../src/modules/scenarios/scenarios-planning-unit.geo.entity';
import { LockStatus } from '../../src/modules/scenarios/lock-status.enum';
import {
LockStatus,
ScenariosPlanningUnitGeoEntity,
} from '@marxan/scenarios-planning-unit';

// TODO monorepo - copy of api-step
export const GivenScenarioPuDataExists = async (
Expand Down
2 changes: 2 additions & 0 deletions api/libs/scenarios-planning-unit/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { LockStatus } from './lock-status.enum';
export { ScenariosPlanningUnitGeoEntity } from './scenarios-planning-unit.geo.entity';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { LockStatus } from './lock-status.enum';

export const scenariosPuDataEntityName = 'scenarios_pu_data';
const scenariosPuDataEntityName = 'scenarios_pu_data';

const toLockEnum: Record<0 | 1 | 2, LockStatus> = Object.freeze({
0: LockStatus.Unstated,
Expand Down
9 changes: 9 additions & 0 deletions api/libs/scenarios-planning-unit/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "../../dist/libs/scenarios-planning-unit"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
11 changes: 10 additions & 1 deletion api/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
"compilerOptions": {
"tsConfigPath": "libs/utils/tsconfig.lib.json"
}
},
"scenarios-planning-unit": {
"type": "library",
"root": "libs/scenarios-planning-unit",
"entryFile": "index",
"sourceRoot": "libs/scenarios-planning-unit/src",
"compilerOptions": {
"tsConfigPath": "libs/scenarios-planning-unit/tsconfig.lib.json"
}
}
}
}
}
4 changes: 3 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@
"@marxan-api/(.*)": "<rootDir>/apps/api/src/$1",
"@marxan-geoprocessing/(.*)": "<rootDir>/apps/geoprocessing/src/$1",
"@marxan/utils/(.*)": "<rootDir>/libs/utils/src/$1",
"@marxan/utils": "<rootDir>/libs/utils/src"
"@marxan/utils": "<rootDir>/libs/utils/src",
"@marxan/scenarios-planning-unit/(.*)": "<rootDir>/libs/scenarios-planning-unit/src/$1",
"@marxan/scenarios-planning-unit": "<rootDir>/libs/scenarios-planning-unit/src"
}
}
}
8 changes: 7 additions & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
],
"@marxan/utils/*": [
"libs/utils/src/*"
],
"@marxan/scenarios-planning-unit": [
"libs/scenarios-planning-unit/src"
],
"@marxan/scenarios-planning-unit/*": [
"libs/scenarios-planning-unit/src/*"
]
}
},
"exclude": [
"node_modules",
"dist"
]
}
}