Skip to content

Commit da0522a

Browse files
author
Abigail Cabascango
committed
feat: TTA-115 implement notification when the endpoint fails for a slow connection
1 parent 84bde1c commit da0522a

File tree

10 files changed

+119
-54
lines changed

10 files changed

+119
-54
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
99
import * as actions from './activity-management.actions';
1010
import { Activity, ActivityStatus } from './../../shared/models/activity.model';
1111
import { ActivityService } from './../services/activity.service';
12+
import { StatusNetworkService } from '../../shared/services/status-network.service';
1213

1314
@Injectable()
1415
export class ActivityEffects {
1516
constructor(
1617
private actions$: Actions,
1718
private activityService: ActivityService,
18-
private toastrService: ToastrService
19+
private toastrService: ToastrService,
20+
private statusNetworkService: StatusNetworkService
1921
) { }
2022

2123
@Effect()
@@ -27,7 +29,7 @@ export class ActivityEffects {
2729
return new actions.LoadActivitiesSuccess(activities);
2830
}),
2931
catchError((error) => {
30-
this.toastrService.error(error.error.message);
32+
this.statusNetworkService.checkTypeError({error, isError: true});
3133
return of(new actions.LoadActivitiesFail(error));
3234
})
3335
)
@@ -45,7 +47,7 @@ export class ActivityEffects {
4547
return new actions.CreateActivitySuccess(activityData);
4648
}),
4749
catchError((error) => {
48-
this.toastrService.error(error.error.message);
50+
this.statusNetworkService.checkTypeError({error, isError: true});
4951
return of(new actions.CreateActivityFail(error));
5052
})
5153
)
@@ -66,7 +68,7 @@ export class ActivityEffects {
6668
return new actions.ArchiveActivitySuccess(activity);
6769
}),
6870
catchError((error) => {
69-
this.toastrService.error(error.error.message);
71+
this.statusNetworkService.checkTypeError({error, isError: true});
7072
return of(new actions.ArchiveActivityFail(error));
7173
})
7274
)
@@ -84,7 +86,7 @@ export class ActivityEffects {
8486
return new actions.UpdateActivitySuccess(activityData);
8587
}),
8688
catchError((error) => {
87-
this.toastrService.error(error.error.message);
89+
this.statusNetworkService.checkTypeError({error, isError: true});
8890
return of(new actions.UpdateActivityFail(error));
8991
})
9092
)
@@ -106,7 +108,7 @@ export class ActivityEffects {
106108
return new actions.UnarchiveActivitySuccess(activityData);
107109
}),
108110
catchError((error) => {
109-
this.toastrService.error(error.error.message);
111+
this.statusNetworkService.checkTypeError({error, isError: true});
110112
return of(new actions.UnarchiveActivityFail(error));
111113
})
112114
)

src/app/modules/customer-management/components/projects-type/services/project-type.service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ export class ProjectTypeService {
1515

1616
getProjectTypes(customerId: any): Observable<ProjectType[]> {
1717
const params = new HttpParams().set('customer_id', customerId.customerId);
18-
return this.http.get<ProjectType[]>(this.baseUrl, { params }).pipe(map((data: { status: any; }) => {
19-
console.log("Here will be return response code Ex :200", data.status)
20-
return data.status
21-
}));
18+
return this.http.get<ProjectType[]>(this.baseUrl, { params });
2219
}
2320

2421
createProjectType(projectTypeData): Observable<any> {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import * as actions from './project-type.actions';
99
import { ProjectType } from '../../../../shared/models';
1010
import { ProjectTypeService } from '../services/project-type.service';
1111
import { ToastrService } from 'ngx-toastr';
12+
import { StatusNetworkService } from '../../../../shared/services/status-network.service';
1213

1314
@Injectable()
1415
export class ProjectTypeEffects {
1516
constructor(
1617
private actions$: Actions,
1718
private projectTypeService: ProjectTypeService,
18-
private toastrService: ToastrService
19+
private toastrService: ToastrService,
20+
private statusNetworkService: StatusNetworkService
1921
) { }
2022

2123
@Effect()
@@ -27,7 +29,7 @@ export class ProjectTypeEffects {
2729
return new actions.LoadProjectTypesSuccess(projectTypes);
2830
}),
2931
catchError((error) => {
30-
this.toastrService.error(error.error.message);
32+
this.statusNetworkService.checkTypeError({error, isError: true});
3133
return of(new actions.LoadProjectTypesFail(error));
3234
})
3335
)
@@ -45,7 +47,7 @@ export class ProjectTypeEffects {
4547
return new actions.CreateProjectTypeSuccess(projectTypeData);
4648
}),
4749
catchError((error) => {
48-
this.toastrService.error(error.error.message);
50+
this.statusNetworkService.checkTypeError({error, isError: true});
4951
return of(new actions.CreateProjectTypeFail(error));
5052
})
5153
)
@@ -63,7 +65,7 @@ export class ProjectTypeEffects {
6365
return new actions.DeleteProjectTypeSuccess(protectTypeId);
6466
}),
6567
catchError((error) => {
66-
this.toastrService.error(error.error.message);
68+
this.statusNetworkService.checkTypeError({error, isError: true});
6769
return of(new actions.DeleteProjectTypeFail(error));
6870
})
6971
)
@@ -81,7 +83,7 @@ export class ProjectTypeEffects {
8183
return new actions.UpdateProjectTypeSuccess(projectTypeData);
8284
}),
8385
catchError((error) => {
84-
this.toastrService.error(error.error.message);
86+
this.statusNetworkService.checkTypeError({error, isError: true});
8587
return of(new actions.UpdateProjectTypeFail(error));
8688
})
8789
)

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { ProjectService } from '../services/project.service';
88
import * as actions from './project.actions';
99
import { ToastrService } from 'ngx-toastr';
1010
import { Status } from 'src/app/modules/shared/models';
11+
import { StatusNetworkService } from '../../../../../shared/services/status-network.service';
1112

1213
@Injectable()
1314
export class ProjectEffects {
1415
constructor(
1516
private actions$: Actions,
1617
private projectService: ProjectService,
17-
private toastrService: ToastrService
18+
private toastrService: ToastrService,
19+
private statusNetworkService: StatusNetworkService
1820
) { }
1921

2022
@Effect()
@@ -26,7 +28,7 @@ export class ProjectEffects {
2628
return new actions.LoadProjectsSuccess(projects);
2729
}),
2830
catchError((error) => {
29-
this.toastrService.error(error.error.message);
31+
this.statusNetworkService.checkTypeError({error, isError: true});
3032
return of(new actions.LoadProjectsFail(error));
3133
})
3234
)
@@ -42,7 +44,7 @@ export class ProjectEffects {
4244
return new actions.LoadCustomerProjectsSuccess(project);
4345
}),
4446
catchError((error) => {
45-
this.toastrService.error(error.error.message);
47+
this.statusNetworkService.checkTypeError({error, isError: true});
4648
return of(new actions.LoadCustomerProjectsFail(error));
4749
})
4850
)
@@ -58,7 +60,7 @@ export class ProjectEffects {
5860
return new actions.LoadRecentProjectsSuccess(projects);
5961
}),
6062
catchError((error) => {
61-
this.toastrService.error(error.error.message);
63+
this.statusNetworkService.checkTypeError({error, isError: true});
6264
return of(new actions.LoadRecentProjectsFail(error));
6365
})
6466
)
@@ -76,7 +78,7 @@ export class ProjectEffects {
7678
return new actions.CreateProjectSuccess(projectData);
7779
}),
7880
catchError((error) => {
79-
this.toastrService.error(error.error.message);
81+
this.statusNetworkService.checkTypeError({error, isError: true});
8082
return of(new actions.CreateProjectFail(error));
8183
})
8284
)
@@ -94,7 +96,7 @@ export class ProjectEffects {
9496
return new actions.UpdateProjectSuccess(projectData);
9597
}),
9698
catchError((error) => {
97-
this.toastrService.error(error.error.message);
99+
this.statusNetworkService.checkTypeError({error, isError: true});
98100
return of(new actions.UpdateProjectFail(error));
99101
})
100102
)
@@ -112,7 +114,7 @@ export class ProjectEffects {
112114
return new actions.DeleteProjectSuccess(projectId);
113115
}),
114116
catchError((error) => {
115-
this.toastrService.error(error.error.message);
117+
this.statusNetworkService.checkTypeError({error, isError: true});
116118
return of(new actions.DeleteProjectFail(error));
117119
})
118120
)
@@ -133,7 +135,7 @@ export class ProjectEffects {
133135
return new actions.UnarchiveProjectSuccess(projectData);
134136
}),
135137
catchError((error) => {
136-
this.toastrService.error(error.error.message);
138+
this.statusNetworkService.checkTypeError({error, isError: true});
137139
return of(new actions.UnarchiveProjectFail(error));
138140
})
139141
)

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
99
import { CustomerService } from '../services/customer.service';
1010
import * as actions from './customer-management.actions';
1111
import { Status } from '../../shared/models/customer.model';
12+
import { StatusNetworkService } from '../../shared/services/status-network.service';
1213

1314
@Injectable()
1415
export class CustomerEffects {
1516
constructor(
1617
private actions$: Actions,
1718
private customerService: CustomerService,
18-
private toastrService: ToastrService
19+
private toastrService: ToastrService,
20+
private statusNetworkService: StatusNetworkService
1921
) { }
2022

2123
@Effect()
@@ -27,7 +29,7 @@ export class CustomerEffects {
2729
return new actions.LoadCustomersSuccess(customers);
2830
}),
2931
catchError((error) => {
30-
this.toastrService.error(error.error.message);
32+
this.statusNetworkService.checkTypeError({error, isError: true});
3133
return of(new actions.LoadCustomersFail(error));
3234
}
3335
)
@@ -46,7 +48,7 @@ export class CustomerEffects {
4648
return new actions.CreateCustomerSuccess(customerData);
4749
}),
4850
catchError((error) => {
49-
this.toastrService.error(error.error.message);
51+
this.statusNetworkService.checkTypeError({error, isError: true});
5052
return of(new actions.CreateCustomerFail(error));
5153
})
5254
)
@@ -64,7 +66,7 @@ export class CustomerEffects {
6466
return new actions.DeleteCustomerSuccesss(customerId);
6567
}),
6668
catchError((error) => {
67-
this.toastrService.error(error.error.message);
69+
this.statusNetworkService.checkTypeError({error, isError: true});
6870
return of(new actions.DeleteCustomerFail(error));
6971
})
7072
)
@@ -82,7 +84,7 @@ export class CustomerEffects {
8284
return new actions.UpdateCustomerSuccess(customerData);
8385
}),
8486
catchError((error) => {
85-
this.toastrService.error(error.error.message);
87+
this.statusNetworkService.checkTypeError({error, isError: true});
8688
return of(new actions.UpdateCustomerFail(error));
8789
})
8890
)
@@ -104,7 +106,7 @@ export class CustomerEffects {
104106
return new actions.UpdateCustomerSuccess(customerData);
105107
}),
106108
catchError((error) => {
107-
this.toastrService.error(error.error.message);
109+
this.statusNetworkService.checkTypeError({error, isError: true});
108110
return of(new actions.UpdateCustomerFail(error));
109111
})
110112
)

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ export class InternetConnectionStatusComponent implements OnInit {
5757
});
5858

5959
ngOnInit(){
60-
// $scope, $http
61-
// $scope.isLoading = function () {
62-
// return $http.pendingRequests.length !== 0;
63-
// };
6460
const connection = navigator.connection;
6561
console.log('navigator component', connection);
6662
if (!connection || !connection.effectiveType) {
@@ -79,10 +75,9 @@ export class InternetConnectionStatusComponent implements OnInit {
7975
this.toastrService.warning('Caution your connection is slow');
8076
this.isFast = false;
8177
} else {
82-
this.toastrService.error('You are offline');
78+
this.toastrService.error('Your request was not completed, you are offline');
8379
this.isFast = false;
8480
}
8581
});
8682
}
87-
8883
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { StatusNetworkService } from './status-network.service';
4+
5+
describe('StatusNetworkService', () => {
6+
let service: StatusNetworkService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(StatusNetworkService);
11+
});
12+
13+
fit('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Injectable } from '@angular/core';
2+
import { ToastrService } from 'ngx-toastr';
3+
4+
export interface ErrorType {
5+
error: any;
6+
message?: string;
7+
isError?: boolean;
8+
}
9+
10+
@Injectable({
11+
providedIn: 'root'
12+
})
13+
export class StatusNetworkService {
14+
15+
constructor(
16+
private toastrService: ToastrService
17+
) { }
18+
19+
checkTypeError(dataError: ErrorType){
20+
const { isError = false, message = 'The server is disconnected', error} = dataError;
21+
const effectiveTypenetwork = navigator.connection;
22+
if(effectiveTypenetwork.effectiveType === '2g'){
23+
this.toastrService.warning('Your request was not completed, your connection is slow');
24+
}else{
25+
if(isError){
26+
const errorMessa = error.error && error.error.message? error.error.message: 'There is an error with the server, your request have not be completed';
27+
this.toastrService.error(errorMessa);
28+
}else{
29+
this.toastrService.warning(message);
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)