Skip to content

Commit e6fe3c6

Browse files
committed
fix(arc-saas): testing edit plan page
testing edit plan page GH-64
1 parent fb647ec commit e6fe3c6

File tree

7 files changed

+162
-39
lines changed

7 files changed

+162
-39
lines changed

projects/saas-ui/src/app/main/commands/edit-features.command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export class EditFeaturesCommand<T> extends PatchAPICommand<T> {
77
constructor(
88
apiService: ApiService,
99
adapter: IAdapter<T>,
10+
planId: string,
1011
appConfig: IAnyObject,
1112
) {
1213
super(
1314
apiService,
1415
adapter,
15-
`https://arc-saas.net/subscription-service/feature-values`,
16+
` ${appConfig.baseApiUrl}${appConfig.subscriptionServiceUrl}/plans/${planId}/features`,
1617
);
1718
}
1819
}
19-
// ${appConfig.baseApiUrl}${appConfig.subscriptionServiceUrl}/plans/${planId}`

projects/saas-ui/src/app/main/commands/get-feature-by-id.command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import {APP_CONFIG} from '@project-lib/app-config';
55
import {IAnyObject} from '@project-lib/core/i-any-object';
66
import {Plan} from '../../shared/models';
77
import {FeatureValues} from '../../shared/models/feature-values.model';
8-
export class GetFeatureByIdCommand<T> extends GetAPICommand<FeatureValues[]> {
8+
import {PlanWithFeatures} from '../../shared/models/plans-features.model';
9+
export class GetFeatureByIdCommand<T> extends GetAPICommand<PlanWithFeatures> {
910
parameters: {};
1011
constructor(
1112
apiService: IApiService,
12-
adapter: IAdapter<FeatureValues[]>,
13+
adapter: IAdapter<PlanWithFeatures>,
1314
planId: string,
1415
appConfig: IAnyObject,
1516
) {

projects/saas-ui/src/app/main/components/add-plan/add-plan.component.ts

Lines changed: 135 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Feature} from '../../../shared/interfaces/features';
1313
import {Features} from '../../../shared/models/feature.model';
1414
import {Plan} from '../../../shared/models';
1515
import {FeatureValues} from '../../../shared/models/feature-values.model';
16+
import {PlanWithFeatures} from '../../../shared/models/plans-features.model';
1617

1718
interface Subtask {
1819
name: string;
@@ -36,7 +37,7 @@ export class AddPlanComponent implements OnInit {
3637
currencyOptions: AnyObject;
3738
selectedFeatures: Features[];
3839
featureOption: Features[];
39-
featureValue: FeatureValues[];
40+
featureValue: PlanWithFeatures | any;
4041
planId: string;
4142
featureId: string;
4243
isEditMode = false;
@@ -152,7 +153,9 @@ export class AddPlanComponent implements OnInit {
152153

153154
this.featureListService
154155
.addFeatures(planFeatureDetailData, this.planId)
155-
.subscribe(featResp => {});
156+
.subscribe(featResp => {
157+
console.log('skip'); //NOSONAR
158+
});
156159
this.toasterService.show('Plan added Successfully');
157160
this.router.navigate(['/main/plans']);
158161
},
@@ -202,53 +205,138 @@ export class AddPlanComponent implements OnInit {
202205
}
203206
}
204207

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+
// });
205227
getPlanbyId() {
206228
this.billingplanService
207229
.getPlanById(this.activateRoute.snapshot.params.id)
208230
.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);
212234

213235
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],
219241
tier: [tierName, Validators.required],
220-
size: [body.size],
242+
size: [response.size],
221243
features: this.fb.group({}),
222244
});
223245
});
224246
this.featureListService
225247
.getFeatureById(this.activateRoute.snapshot.params.id)
226248
.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;
232254
this.createFeatureControls();
233255
const featuresGroup = this.addPlanForm.get('features') as FormGroup;
234256
if (featuresGroup) {
235257
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+
);
241262
});
242263
}
243264
});
244265
}
245266

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+
246333
editPlan() {
247334
if (this.addPlanForm.valid) {
248335
const domainData = this.addPlanForm.value;
249336
domainData.price = parseFloat(domainData.price);
250337

251338
const featuresGroup = this.addPlanForm.get('features') as FormGroup;
339+
252340
const selectedFeatures = featuresGroup
253341
? Object.keys(featuresGroup.controls)
254342
.filter(
@@ -258,15 +346,21 @@ export class AddPlanComponent implements OnInit {
258346
)
259347
.reduce(
260348
(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+
);
262352
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+
};
264357
}
265358
return acc;
266359
},
267360
{} as {[key: string]: any},
268361
)
269362
: {};
363+
console.log(this.addPlanForm.value);
270364
const generalDetailsData = {
271365
name: domainData.name,
272366
billingCycleId: domainData.billingCycleId,
@@ -289,24 +383,34 @@ export class AddPlanComponent implements OnInit {
289383
selectedFeatures,
290384
)
291385
.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);
293388
return {
294-
featureKey: feature ? feature.id : null,
295-
strategyKey: 'plan',
389+
id: selectedFeatures[key].id,
390+
featureKey: feature.id,
391+
strategyKey: 'Plan',
296392
strategyEntityId: this.activateRoute.snapshot.params.id,
297393
status: true,
298-
value: selectedFeatures[key].toString(), // Ensure value is always a string
394+
value: selectedFeatures[key].value?.toString(),
299395
};
300396
})
301-
.filter(item => item.featureKey !== null);
397+
.filter(item => item.id !== null);
398+
console.log(updateFeatureDetails);
302399
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()
305409
} else {
410+
// Handle form validation errors if necessary
306411
console.error('Form is invalid');
307412
}
308413
}
309-
310414
onTierChange(selectedTier: string): void {
311415
this.showStorageSize = selectedTier === 'PREMIUM';
312416
if (!this.showStorageSize) {

projects/saas-ui/src/app/shared/models/feature.model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import {FeatureValues} from './feature-values.model';
2+
13
export class Features {
24
id?: string;
35
name: string;
46
description: string;
57
key: string;
68
type: 'boolean' | 'number' | 'string' | 'object';
79
defaultValue: any;
8-
value?: string;
10+
value?: FeatureValues;
911
constructor(data?: Partial<Features>) {
1012
this.id = data?.id;
1113
this.name = data.name;

projects/saas-ui/src/app/shared/models/plan.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export class Plan {
1010
metadata?: AnyObject;
1111
billingCycleId: string;
1212
currencyId: string;
13+
size?: string;
1314
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Feature} from '../interfaces/features';
2+
import {Features} from './feature.model';
3+
4+
export class PlanWithFeatures {
5+
name: string;
6+
tier: string;
7+
size: string;
8+
features: Features[];
9+
}

projects/saas-ui/src/app/shared/services/feature-list-service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {FeatureValues} from '../models/feature-values.model';
2020
import {AuthTokenSkipHeader} from '@project-lib/core/constants';
2121
import {EditFeaturesCommand} from '../../main/commands/edit-features.command';
2222
import {GetFeatureByIdCommand} from '../../main/commands/get-feature-by-id.command';
23+
import {PlanWithFeatures} from '../models/plans-features.model';
2324

2425
interface BackendFilter<MT extends object = AnyObject> {
2526
where?: Where<MT>;
@@ -66,17 +67,22 @@ export class FeatureListService {
6667
return command.execute();
6768
}
6869

69-
editFeatures(featureValue: FeatureValues[]) {
70+
editFeatures(featureValue: FeatureValues[], planId: string) {
7071
const command: EditFeaturesCommand<FeatureValues[]> =
71-
new EditFeaturesCommand(this.apiService, this.anyAdapter, this.appConfig);
72+
new EditFeaturesCommand(
73+
this.apiService,
74+
this.anyAdapter,
75+
planId,
76+
this.appConfig,
77+
);
7278
command.parameters = {
7379
data: featureValue,
7480
};
7581
return command.execute();
7682
}
7783

7884
getFeatureById(planId: string) {
79-
const command: GetFeatureByIdCommand<FeatureValues[]> =
85+
const command: GetFeatureByIdCommand<PlanWithFeatures> =
8086
new GetFeatureByIdCommand(
8187
this.apiService,
8288
this.anyAdapter,

0 commit comments

Comments
 (0)