@@ -13,6 +13,7 @@ import {Feature} from '../../../shared/interfaces/features';
13
13
import { Features } from '../../../shared/models/feature.model' ;
14
14
import { Plan } from '../../../shared/models' ;
15
15
import { FeatureValues } from '../../../shared/models/feature-values.model' ;
16
+ import { PlanWithFeatures } from '../../../shared/models/plans-features.model' ;
16
17
17
18
interface Subtask {
18
19
name : string ;
@@ -36,7 +37,7 @@ export class AddPlanComponent implements OnInit {
36
37
currencyOptions : AnyObject ;
37
38
selectedFeatures : Features [ ] ;
38
39
featureOption : Features [ ] ;
39
- featureValue : FeatureValues [ ] ;
40
+ featureValue : PlanWithFeatures | any ;
40
41
planId : string ;
41
42
featureId : string ;
42
43
isEditMode = false ;
@@ -152,7 +153,9 @@ export class AddPlanComponent implements OnInit {
152
153
153
154
this . featureListService
154
155
. addFeatures ( planFeatureDetailData , this . planId )
155
- . subscribe ( featResp => { } ) ;
156
+ . subscribe ( featResp => {
157
+ console . log ( 'skip' ) ; //NOSONAR
158
+ } ) ;
156
159
this . toasterService . show ( 'Plan added Successfully' ) ;
157
160
this . router . navigate ( [ '/main/plans' ] ) ;
158
161
} ,
@@ -202,53 +205,138 @@ export class AddPlanComponent implements OnInit {
202
205
}
203
206
}
204
207
208
+ // getPlanbyId() {
209
+ // this.billingplanService
210
+ // .getPlanById(this.activateRoute.snapshot.params.id)
211
+ // .subscribe(response => {
212
+ // // const body = JSON.parse(JSON.stringify(response)).body;
213
+ // const tierName: string = response.tier;
214
+ // body.tier = JSON.stringify(body.tier);
215
+
216
+ // this.addPlanForm = this.fb.group({
217
+ // name: [body.name, Validators.required],
218
+ // description: [body.description, Validators.required],
219
+ // price: [body.price, Validators.required],
220
+ // currencyId: [body.currencyId, Validators.required],
221
+ // billingCycleId: [body.billingCycleId, Validators.required],
222
+ // tier: [tierName, Validators.required],
223
+ // size: [body.size],
224
+ // features: this.fb.group({}),
225
+ // });
226
+ // });
205
227
getPlanbyId ( ) {
206
228
this . billingplanService
207
229
. getPlanById ( this . activateRoute . snapshot . params . id )
208
230
. subscribe ( response => {
209
- let body = JSON . parse ( JSON . stringify ( response ) ) . body ;
210
- const tierName : string = body . tier ;
211
- body . tier = JSON . stringify ( body . tier ) ;
231
+ // const body = JSON.parse(JSON.stringify(response)).body;
232
+ const tierName = response . tier ;
233
+ // response .tier = JSON.stringify(body.tier);
212
234
213
235
this . addPlanForm = this . fb . group ( {
214
- name : [ body . name , Validators . required ] ,
215
- description : [ body . description , Validators . required ] ,
216
- price : [ body . price , Validators . required ] ,
217
- currencyId : [ body . currencyId , Validators . required ] ,
218
- billingCycleId : [ body . billingCycleId , Validators . required ] ,
236
+ name : [ response . name , Validators . required ] ,
237
+ description : [ response . description , Validators . required ] ,
238
+ price : [ response . price , Validators . required ] ,
239
+ currencyId : [ response . currencyId , Validators . required ] ,
240
+ billingCycleId : [ response . billingCycleId , Validators . required ] ,
219
241
tier : [ tierName , Validators . required ] ,
220
- size : [ body . size ] ,
242
+ size : [ response . size ] ,
221
243
features : this . fb . group ( { } ) ,
222
244
} ) ;
223
245
} ) ;
224
246
this . featureListService
225
247
. getFeatureById ( this . activateRoute . snapshot . params . id )
226
248
. subscribe ( resp => {
227
- let featureBody = JSON . parse ( JSON . stringify ( resp ) ) . body ;
228
-
229
- const features = featureBody . features ;
230
-
231
- this . featureValue = features ;
249
+ // const featureBody = JSON.parse(JSON.stringify(resp)).body;
250
+ // const features = resp.features;
251
+ const features = resp . features ;
252
+ // (f as any).key
253
+ this . featureValue = resp ;
232
254
this . createFeatureControls ( ) ;
233
255
const featuresGroup = this . addPlanForm . get ( 'features' ) as FormGroup ;
234
256
if ( featuresGroup ) {
235
257
Object . keys ( featuresGroup . controls ) . forEach ( controlName => {
236
- featuresGroup
237
- . get ( controlName )
238
- ?. setValue (
239
- features . find ( item => item . key === controlName ) ?. value ?. value ,
240
- ) ;
258
+ featuresGroup . get ( controlName ) ?. setValue (
259
+ // features.find(item => item.key === controlName)?.value?.value,
260
+ features . find ( item => item . key === controlName ) ?. value ?. value ,
261
+ ) ;
241
262
} ) ;
242
263
}
243
264
} ) ;
244
265
}
245
266
267
+ // editPlan() {
268
+ // if (this.addPlanForm.valid) {
269
+ // const domainData = this.addPlanForm.value;
270
+ // domainData.price = parseFloat(domainData.price);
271
+
272
+ // const featuresGroup = this.addPlanForm.get('features') as FormGroup;
273
+ // const selectedFeatures = featuresGroup
274
+ // ? Object.keys(featuresGroup.controls)
275
+ // .filter(
276
+ // key =>
277
+ // featuresGroup.get(key)?.value !== null &&
278
+ // featuresGroup.get(key)?.value !== '',
279
+ // )
280
+ // .reduce(
281
+ // (acc, key) => {
282
+ // const feature = this.featureOption.find(f => f.key === key);
283
+ // if (feature) {
284
+ // acc[feature.key] = featuresGroup.get(key)?.value;
285
+ // }
286
+ // return acc;
287
+ // },
288
+ // {} as {[key: string]: any},
289
+ // )
290
+ // : {};
291
+ // const generalDetailsData = {
292
+ // name: domainData.name,
293
+ // billingCycleId: domainData.billingCycleId,
294
+ // price: domainData.price,
295
+ // currencyId: domainData.currencyId,
296
+ // description: domainData.description,
297
+ // tier: domainData.tier,
298
+ // size: domainData.size,
299
+ // };
300
+
301
+ // domainData.features = selectedFeatures;
302
+
303
+ // this.billingplanService
304
+ // .editPlan(generalDetailsData, this.activateRoute.snapshot.params.id)
305
+ // .subscribe(res => {
306
+ // this.router.navigate(['/main/plans']);
307
+ // });
308
+
309
+ // const updateFeatureDetails: FeatureValues[] = Object.keys(
310
+ // selectedFeatures,
311
+ // )
312
+ // .map(key => {
313
+ // const feature = this.featureOption.find(f => f.key === key);
314
+ // return {
315
+ // featureKey: feature ? feature.id : null,
316
+ // strategyKey: 'plan',
317
+ // strategyEntityId: this.activateRoute.snapshot.params.id,
318
+ // status: true,
319
+ // value: selectedFeatures[key].toString(), // Ensure value is always a string
320
+ // };
321
+ // })
322
+ // .filter(item => item.featureKey !== null);
323
+ // this.featureListService
324
+ // .editFeatures(updateFeatureDetails)
325
+ // .subscribe(respFeature => {
326
+ // console.log('skip'); //NOSONAR
327
+ // });
328
+ // } else {
329
+ // console.error('Form is invalid');
330
+ // }
331
+ // }
332
+
246
333
editPlan ( ) {
247
334
if ( this . addPlanForm . valid ) {
248
335
const domainData = this . addPlanForm . value ;
249
336
domainData . price = parseFloat ( domainData . price ) ;
250
337
251
338
const featuresGroup = this . addPlanForm . get ( 'features' ) as FormGroup ;
339
+
252
340
const selectedFeatures = featuresGroup
253
341
? Object . keys ( featuresGroup . controls )
254
342
. filter (
@@ -258,15 +346,21 @@ export class AddPlanComponent implements OnInit {
258
346
)
259
347
. reduce (
260
348
( acc , key ) => {
261
- const feature = this . featureOption . find ( f => f . key === key ) ;
349
+ const feature = this . featureValue . find (
350
+ f => ( f as any ) . key === key ,
351
+ ) ;
262
352
if ( feature ) {
263
- acc [ feature . key ] = featuresGroup . get ( key ) ?. value ;
353
+ acc [ feature . id ] = {
354
+ id : ( feature . value as any ) . id ,
355
+ value : featuresGroup . get ( key ) ?. value ,
356
+ } ;
264
357
}
265
358
return acc ;
266
359
} ,
267
360
{ } as { [ key : string ] : any } ,
268
361
)
269
362
: { } ;
363
+ console . log ( this . addPlanForm . value ) ;
270
364
const generalDetailsData = {
271
365
name : domainData . name ,
272
366
billingCycleId : domainData . billingCycleId ,
@@ -289,24 +383,34 @@ export class AddPlanComponent implements OnInit {
289
383
selectedFeatures ,
290
384
)
291
385
. map ( key => {
292
- const feature = this . featureOption . find ( f => f . key === key ) ;
386
+ const feature = this . featureValue . find ( f => f . id === key ) ;
387
+ console . log ( feature ) ;
293
388
return {
294
- featureKey : feature ? feature . id : null ,
295
- strategyKey : 'plan' ,
389
+ id : selectedFeatures [ key ] . id ,
390
+ featureKey : feature . id ,
391
+ strategyKey : 'Plan' ,
296
392
strategyEntityId : this . activateRoute . snapshot . params . id ,
297
393
status : true ,
298
- value : selectedFeatures [ key ] . toString ( ) , // Ensure value is always a string
394
+ value : selectedFeatures [ key ] . value ?. toString ( ) ,
299
395
} ;
300
396
} )
301
- . filter ( item => item . featureKey !== null ) ;
397
+ . filter ( item => item . id !== null ) ;
398
+ console . log ( updateFeatureDetails ) ;
302
399
this . featureListService
303
- . editFeatures ( updateFeatureDetails )
304
- . subscribe ( respFeature => { } ) ;
400
+ . editFeatures (
401
+ updateFeatureDetails ,
402
+ this . activateRoute . snapshot . params . id ,
403
+ )
404
+ . subscribe ( respFeature => {
405
+ console . log ( respFeature ) ;
406
+ } ) ;
407
+
408
+ // this.featureListService.editFeatures()
305
409
} else {
410
+ // Handle form validation errors if necessary
306
411
console . error ( 'Form is invalid' ) ;
307
412
}
308
413
}
309
-
310
414
onTierChange ( selectedTier : string ) : void {
311
415
this . showStorageSize = selectedTier === 'PREMIUM' ;
312
416
if ( ! this . showStorageSize ) {
0 commit comments