Skip to content

Commit 8e72487

Browse files
author
Abigail Cabascango
committed
refactor: TTA-115 solve review comments
1 parent 37cec9b commit 8e72487

File tree

10 files changed

+68
-69
lines changed

10 files changed

+68
-69
lines changed

src/app/modules/activities-management/store/activity-management.effects.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ActivityEffects {
2929
return new actions.LoadActivitiesSuccess(activities);
3030
}),
3131
catchError((error) => {
32-
this.statusNetworkService.checkTypeError({error, isError: true});
32+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
3333
return of(new actions.LoadActivitiesFail(error));
3434
})
3535
)
@@ -47,7 +47,7 @@ export class ActivityEffects {
4747
return new actions.CreateActivitySuccess(activityData);
4848
}),
4949
catchError((error) => {
50-
this.statusNetworkService.checkTypeError({error, isError: true});
50+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
5151
return of(new actions.CreateActivityFail(error));
5252
})
5353
)
@@ -68,7 +68,7 @@ export class ActivityEffects {
6868
return new actions.ArchiveActivitySuccess(activity);
6969
}),
7070
catchError((error) => {
71-
this.statusNetworkService.checkTypeError({error, isError: true});
71+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
7272
return of(new actions.ArchiveActivityFail(error));
7373
})
7474
)
@@ -86,7 +86,7 @@ export class ActivityEffects {
8686
return new actions.UpdateActivitySuccess(activityData);
8787
}),
8888
catchError((error) => {
89-
this.statusNetworkService.checkTypeError({error, isError: true});
89+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
9090
return of(new actions.UpdateActivityFail(error));
9191
})
9292
)
@@ -108,7 +108,7 @@ export class ActivityEffects {
108108
return new actions.UnarchiveActivitySuccess(activityData);
109109
}),
110110
catchError((error) => {
111-
this.statusNetworkService.checkTypeError({error, isError: true});
111+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
112112
return of(new actions.UnarchiveActivityFail(error));
113113
})
114114
)

src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ProjectTypeEffects {
2929
return new actions.LoadProjectTypesSuccess(projectTypes);
3030
}),
3131
catchError((error) => {
32-
this.statusNetworkService.checkTypeError({error, isError: true});
32+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
3333
return of(new actions.LoadProjectTypesFail(error));
3434
})
3535
)
@@ -47,7 +47,7 @@ export class ProjectTypeEffects {
4747
return new actions.CreateProjectTypeSuccess(projectTypeData);
4848
}),
4949
catchError((error) => {
50-
this.statusNetworkService.checkTypeError({error, isError: true});
50+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
5151
return of(new actions.CreateProjectTypeFail(error));
5252
})
5353
)
@@ -65,7 +65,7 @@ export class ProjectTypeEffects {
6565
return new actions.DeleteProjectTypeSuccess(protectTypeId);
6666
}),
6767
catchError((error) => {
68-
this.statusNetworkService.checkTypeError({error, isError: true});
68+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
6969
return of(new actions.DeleteProjectTypeFail(error));
7070
})
7171
)
@@ -83,7 +83,7 @@ export class ProjectTypeEffects {
8383
return new actions.UpdateProjectTypeSuccess(projectTypeData);
8484
}),
8585
catchError((error) => {
86-
this.statusNetworkService.checkTypeError({error, isError: true});
86+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
8787
return of(new actions.UpdateProjectTypeFail(error));
8888
})
8989
)

src/app/modules/customer-management/components/projects/components/store/project.effects.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ProjectEffects {
2828
return new actions.LoadProjectsSuccess(projects);
2929
}),
3030
catchError((error) => {
31-
this.statusNetworkService.checkTypeError({error, isError: true});
31+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
3232
return of(new actions.LoadProjectsFail(error));
3333
})
3434
)
@@ -44,7 +44,7 @@ export class ProjectEffects {
4444
return new actions.LoadCustomerProjectsSuccess(project);
4545
}),
4646
catchError((error) => {
47-
this.statusNetworkService.checkTypeError({error, isError: true});
47+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
4848
return of(new actions.LoadCustomerProjectsFail(error));
4949
})
5050
)
@@ -60,7 +60,7 @@ export class ProjectEffects {
6060
return new actions.LoadRecentProjectsSuccess(projects);
6161
}),
6262
catchError((error) => {
63-
this.statusNetworkService.checkTypeError({error, isError: true});
63+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
6464
return of(new actions.LoadRecentProjectsFail(error));
6565
})
6666
)
@@ -78,7 +78,7 @@ export class ProjectEffects {
7878
return new actions.CreateProjectSuccess(projectData);
7979
}),
8080
catchError((error) => {
81-
this.statusNetworkService.checkTypeError({error, isError: true});
81+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
8282
return of(new actions.CreateProjectFail(error));
8383
})
8484
)
@@ -96,7 +96,7 @@ export class ProjectEffects {
9696
return new actions.UpdateProjectSuccess(projectData);
9797
}),
9898
catchError((error) => {
99-
this.statusNetworkService.checkTypeError({error, isError: true});
99+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
100100
return of(new actions.UpdateProjectFail(error));
101101
})
102102
)
@@ -114,7 +114,7 @@ export class ProjectEffects {
114114
return new actions.DeleteProjectSuccess(projectId);
115115
}),
116116
catchError((error) => {
117-
this.statusNetworkService.checkTypeError({error, isError: true});
117+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
118118
return of(new actions.DeleteProjectFail(error));
119119
})
120120
)
@@ -135,7 +135,7 @@ export class ProjectEffects {
135135
return new actions.UnarchiveProjectSuccess(projectData);
136136
}),
137137
catchError((error) => {
138-
this.statusNetworkService.checkTypeError({error, isError: true});
138+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
139139
return of(new actions.UnarchiveProjectFail(error));
140140
})
141141
)

src/app/modules/customer-management/store/customer-management.effects.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class CustomerEffects {
2929
return new actions.LoadCustomersSuccess(customers);
3030
}),
3131
catchError((error) => {
32-
this.statusNetworkService.checkTypeError({error, isError: true});
32+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
3333
return of(new actions.LoadCustomersFail(error));
3434
}
3535
)
@@ -48,7 +48,7 @@ export class CustomerEffects {
4848
return new actions.CreateCustomerSuccess(customerData);
4949
}),
5050
catchError((error) => {
51-
this.statusNetworkService.checkTypeError({error, isError: true});
51+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
5252
return of(new actions.CreateCustomerFail(error));
5353
})
5454
)
@@ -66,7 +66,7 @@ export class CustomerEffects {
6666
return new actions.DeleteCustomerSuccesss(customerId);
6767
}),
6868
catchError((error) => {
69-
this.statusNetworkService.checkTypeError({error, isError: true});
69+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
7070
return of(new actions.DeleteCustomerFail(error));
7171
})
7272
)
@@ -84,7 +84,7 @@ export class CustomerEffects {
8484
return new actions.UpdateCustomerSuccess(customerData);
8585
}),
8686
catchError((error) => {
87-
this.statusNetworkService.checkTypeError({error, isError: true});
87+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
8888
return of(new actions.UpdateCustomerFail(error));
8989
})
9090
)
@@ -106,7 +106,7 @@ export class CustomerEffects {
106106
return new actions.UpdateCustomerSuccess(customerData);
107107
}),
108108
catchError((error) => {
109-
this.statusNetworkService.checkTypeError({error, isError: true});
109+
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
110110
return of(new actions.UpdateCustomerFail(error));
111111
})
112112
)

src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ export class ConnectionDirective implements OnInit {
1616
ngOnInit() {
1717
const { effectiveType } = navigator.connection;
1818
let networkSatus;
19-
if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){
20-
networkSatus = this.offlineSrc;
21-
}
22-
2319
if (/\fast-5g|3g|4g/.test(effectiveType)) {
2420
networkSatus = this.fastSrc;
21+
return
2522
}
26-
2723
if (/\slow-2g|2g/.test(effectiveType)) {
2824
networkSatus = this.slowSrc;
25+
return
2926
}
27+
networkSatus = this.offlineSrc;
3028

3129
this.host.nativeElement.setAttribute('src', networkSatus);
3230
}
33-
3431
}

src/app/modules/internet-connection-status/internet-connection-status.component.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,18 @@ export class InternetConnectionStatusComponent implements OnInit {
6767
.subscribe((effectiveType: string) => {
6868

6969
this.connectionType = effectiveType;
70-
71-
if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){
70+
71+
if (/\fast-5g|3g|4g/.test(effectiveType)) {
7272
this.toastrService.error('Your request was not completed, you are offline');
73-
this.isFast = false;
74-
}
75-
76-
if (/\fast-5g|3g|4g/.test(effectiveType)){
7773
this.isFast = true;
74+
return
7875
}
79-
8076
if (/\slow-2g|2g/.test(effectiveType)) {
8177
this.toastrService.warning('Caution your connection is slow');
8278
this.isFast = false;
79+
return
8380
}
81+
this.isFast = false;
8482
});
8583
}
8684
}

src/app/modules/shared/services/status-network.service.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ describe('StatusNetworkService', () => {
2424
service = TestBed.inject(StatusNetworkService);
2525
});
2626

27-
it('checkTypeError is error', () => {
27+
it('showTypeToastrServiceAlert is error', () => {
2828
const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: true};
2929
spyOn(toastrServiceStub, 'error');
30-
service.checkTypeError(errorType);
30+
service.showTypeToastrServiceAlert(errorType);
3131
expect(toastrServiceStub.error).toHaveBeenCalled();
3232
});
3333

34-
it('checkTypeError is warning with message', () => {
34+
it('showTypeToastrServiceAlert is warning with message', () => {
3535
const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: false};
3636
spyOn(toastrServiceStub, 'warning');
37-
service.checkTypeError(errorType);
37+
service.showTypeToastrServiceAlert(errorType);
3838
expect(toastrServiceStub.warning).toHaveBeenCalled();
3939
});
4040

41-
it('checkTypeError is warning without message', () => {
41+
it('showTypeToastrServiceAlert is warning without message', () => {
4242
const errorType: ErrorType = {error: catchError, isError: false};
4343
spyOn(toastrServiceStub, 'warning');
44-
service.checkTypeError(errorType);
44+
service.showTypeToastrServiceAlert(errorType);
4545
expect(toastrServiceStub.warning).toHaveBeenCalled();
4646
});
4747
});

src/app/modules/shared/services/status-network.service.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ export class StatusNetworkService {
1616
private toastrService: ToastrService
1717
) { }
1818

19-
checkTypeError(dataError: ErrorType){
20-
const { isError = false, message = 'The server is disconnected', error} = dataError;
19+
showTypeToastrServiceAlert(dataError: ErrorType) {
20+
const { isError = false, message = 'The server is disconnected', error } = dataError;
2121
const effectiveTypenetwork = navigator.connection;
22-
if ((effectiveTypenetwork.effectiveType !== '2g')){
23-
if (!isError){
24-
this.toastrService.warning(message);
25-
}
26-
if (isError){
27-
const errorMessa = error.error && error.error.message ? error.error.message : 'There is an error with the server, your request have not be completed';
28-
this.toastrService.error(errorMessa);
29-
}
22+
23+
if (effectiveTypenetwork.effectiveType === '2g') {
24+
this.toastrService.warning('Your request was not completed, your connection is slow');
25+
return
3026
}
31-
this.toastrService.warning('Your request was not completed, your connection is slow');
32-
}
33-
}
27+
28+
if (!isError) {
29+
this.toastrService.warning(message);
30+
return
31+
}
32+
33+
const errorMessa = (error.error && error.error.message ? error.error.message :
34+
'There was an error in the server, your request was not completed');
35+
this.toastrService.error(errorMessa);
36+
37+
}}

0 commit comments

Comments
 (0)