1- import { Plan , PlanType , TopographicBoundary } from '@domain/entities/Plan' ;
1+ import { Plan , PlanProps , PlanType , TopographicBoundary } from '@domain/entities/Plan' ;
22import { Logger , RepoOptions } from '@domain/types/Common' ;
33import { PlanRepositoryInterface } from '@domain/interfaces/repositories/PlanRepositoryInterface' ;
44import NotFoundError from '@domain/errors/NotFoundError' ;
55import BadRequestError from '@domain/errors/BadRequestError' ;
6+ import { ComputePlanEmbellishments } from '@use-cases/plan/ComputePlanEmbellishments' ;
67
78export interface EditTopoBoundaryRequest {
89 plan_id : string ;
@@ -11,16 +12,24 @@ export interface EditTopoBoundaryRequest {
1112}
1213
1314export class EditTopoBoundary {
15+ private readonly computeEmbellishments : ComputePlanEmbellishments ;
16+
1417 constructor (
1518 private readonly logger : Logger ,
1619 private readonly planRepo : PlanRepositoryInterface ,
17- ) { }
20+ ) {
21+ this . computeEmbellishments = new ComputePlanEmbellishments ( logger ) ;
22+ }
1823
1924 async execute ( data : EditTopoBoundaryRequest ) : Promise < Plan > {
2025 this . logger . info ( 'EditTopoBoundary' , data ) ;
2126
2227 const filter = data . options ?. filter || { } ;
23- let plan = await this . planRepo . getPlanById ( data . plan_id , { projection : { type : 1 } , filter } ) ;
28+ let plan = await this . planRepo . getPlanById ( data . plan_id , {
29+ projection : { type : 1 , coordinates : 1 , topographic_setting : 1 } ,
30+ filter,
31+ } ) ;
32+
2433 if ( ! plan ) {
2534 throw new NotFoundError ( 'Plan not found' ) ;
2635 }
@@ -46,7 +55,25 @@ export class EditTopoBoundary {
4655 data . boundary . coordinates . push ( data . boundary . coordinates [ 0 ] ) ;
4756 }
4857
49- plan = await this . planRepo . editPlan ( data . plan_id , { topographic_boundary : data . boundary } , data . options ) ;
58+ // compute embellishments
59+ const embellishmentCoordinates = [ ...data . boundary . coordinates , ...( plan . coordinates || [ ] ) ] ;
60+ const embellishments = this . computeEmbellishments . execute ( { coordinates : embellishmentCoordinates } ) ;
61+
62+ const update : Partial < PlanProps > = {
63+ topographic_boundary : data . boundary ,
64+ font_size : embellishments . font_size ,
65+ beacon_size : embellishments . beacon_size ,
66+ label_size : embellishments . label_size ,
67+ footer_size : embellishments . footer_size ,
68+ } ;
69+
70+ if ( plan . topographic_setting ) {
71+ plan . topographic_setting . point_label_scale = embellishments . point_label_scale ;
72+ plan . topographic_setting . contour_label_scale = embellishments . contour_label_scale ;
73+ update . topographic_setting = plan . topographic_setting ;
74+ }
75+
76+ plan = await this . planRepo . editPlan ( data . plan_id , update , data . options ) ;
5077 if ( ! plan ) {
5178 throw new NotFoundError ( 'Plan not found' ) ;
5279 }
0 commit comments