-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-pu-grid): set project grid shape once geometries were set
- Loading branch information
Showing
5 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
api/apps/api/src/modules/projects/planning-unit-grid/planning-unit-grid-set.saga.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ICommand, ofType, Saga } from '@nestjs/cqrs'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import { CustomPlanningUnitGridSet } from '../events/custom-planning-unit-grid-set.event'; | ||
import { SetProjectGridFromShapefile } from './set-project-grid-from-shapefile.command'; | ||
import { ProjectId } from './project.id'; | ||
|
||
export class PlanningUnitGridSetSaga { | ||
@Saga() | ||
puGridSet = (events$: Observable<any>): Observable<ICommand> => | ||
events$.pipe( | ||
ofType(CustomPlanningUnitGridSet), | ||
map( | ||
(event) => | ||
new SetProjectGridFromShapefile(new ProjectId(event.projectId)), | ||
), | ||
); | ||
} |
14 changes: 13 additions & 1 deletion
14
api/apps/api/src/modules/projects/planning-unit-grid/planning-unit-grid.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ps/api/src/modules/projects/planning-unit-grid/set-project-grid-from-shapefile.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Command } from '@nestjs-architects/typed-cqrs'; | ||
import { ProjectId } from './project.id'; | ||
|
||
export class SetProjectGridFromShapefile extends Command<void> { | ||
constructor(public readonly projectId: ProjectId) { | ||
super(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ps/api/src/modules/projects/planning-unit-grid/set-project-grid-from-shapefile.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { CommandHandler, IInferredCommandHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { | ||
PlanningUnitGridShape, | ||
Project, | ||
} from '@marxan-api/modules/projects/project.api.entity'; | ||
import { SetProjectGridFromShapefile } from './set-project-grid-from-shapefile.command'; | ||
|
||
@CommandHandler(SetProjectGridFromShapefile) | ||
export class SetProjectGridFromShapefileHandler | ||
implements IInferredCommandHandler<SetProjectGridFromShapefile> { | ||
constructor( | ||
@InjectRepository(Project) private readonly projects: Repository<Project>, | ||
) {} | ||
|
||
async execute({ projectId }: SetProjectGridFromShapefile): Promise<void> { | ||
await this.projects.update( | ||
{ | ||
id: projectId.value, | ||
}, | ||
{ | ||
planningUnitGridShape: PlanningUnitGridShape.fromShapefile, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters