Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: TTA-115 solve review comments
  • Loading branch information
Abigail Cabascango committed Oct 11, 2022
commit 8e724879a1f4741071a02d43b2a5afd1327ec374
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ActivityEffects {
return new actions.LoadActivitiesSuccess(activities);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadActivitiesFail(error));
})
)
Expand All @@ -47,7 +47,7 @@ export class ActivityEffects {
return new actions.CreateActivitySuccess(activityData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateActivityFail(error));
})
)
Expand All @@ -68,7 +68,7 @@ export class ActivityEffects {
return new actions.ArchiveActivitySuccess(activity);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.ArchiveActivityFail(error));
})
)
Expand All @@ -86,7 +86,7 @@ export class ActivityEffects {
return new actions.UpdateActivitySuccess(activityData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateActivityFail(error));
})
)
Expand All @@ -108,7 +108,7 @@ export class ActivityEffects {
return new actions.UnarchiveActivitySuccess(activityData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UnarchiveActivityFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ProjectTypeEffects {
return new actions.LoadProjectTypesSuccess(projectTypes);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadProjectTypesFail(error));
})
)
Expand All @@ -47,7 +47,7 @@ export class ProjectTypeEffects {
return new actions.CreateProjectTypeSuccess(projectTypeData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateProjectTypeFail(error));
})
)
Expand All @@ -65,7 +65,7 @@ export class ProjectTypeEffects {
return new actions.DeleteProjectTypeSuccess(protectTypeId);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.DeleteProjectTypeFail(error));
})
)
Expand All @@ -83,7 +83,7 @@ export class ProjectTypeEffects {
return new actions.UpdateProjectTypeSuccess(projectTypeData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateProjectTypeFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ProjectEffects {
return new actions.LoadProjectsSuccess(projects);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadProjectsFail(error));
})
)
Expand All @@ -44,7 +44,7 @@ export class ProjectEffects {
return new actions.LoadCustomerProjectsSuccess(project);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadCustomerProjectsFail(error));
})
)
Expand All @@ -60,7 +60,7 @@ export class ProjectEffects {
return new actions.LoadRecentProjectsSuccess(projects);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadRecentProjectsFail(error));
})
)
Expand All @@ -78,7 +78,7 @@ export class ProjectEffects {
return new actions.CreateProjectSuccess(projectData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateProjectFail(error));
})
)
Expand All @@ -96,7 +96,7 @@ export class ProjectEffects {
return new actions.UpdateProjectSuccess(projectData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateProjectFail(error));
})
)
Expand All @@ -114,7 +114,7 @@ export class ProjectEffects {
return new actions.DeleteProjectSuccess(projectId);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.DeleteProjectFail(error));
})
)
Expand All @@ -135,7 +135,7 @@ export class ProjectEffects {
return new actions.UnarchiveProjectSuccess(projectData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UnarchiveProjectFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CustomerEffects {
return new actions.LoadCustomersSuccess(customers);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.LoadCustomersFail(error));
}
)
Expand All @@ -48,7 +48,7 @@ export class CustomerEffects {
return new actions.CreateCustomerSuccess(customerData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.CreateCustomerFail(error));
})
)
Expand All @@ -66,7 +66,7 @@ export class CustomerEffects {
return new actions.DeleteCustomerSuccesss(customerId);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.DeleteCustomerFail(error));
})
)
Expand All @@ -84,7 +84,7 @@ export class CustomerEffects {
return new actions.UpdateCustomerSuccess(customerData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateCustomerFail(error));
})
)
Expand All @@ -106,7 +106,7 @@ export class CustomerEffects {
return new actions.UpdateCustomerSuccess(customerData);
}),
catchError((error) => {
this.statusNetworkService.checkTypeError({error, isError: true});
this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true});
return of(new actions.UpdateCustomerFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ export class ConnectionDirective implements OnInit {
ngOnInit() {
const { effectiveType } = navigator.connection;
let networkSatus;
if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){
networkSatus = this.offlineSrc;
}

if (/\fast-5g|3g|4g/.test(effectiveType)) {
networkSatus = this.fastSrc;
return
}

if (/\slow-2g|2g/.test(effectiveType)) {
networkSatus = this.slowSrc;
return
}
networkSatus = this.offlineSrc;

this.host.nativeElement.setAttribute('src', networkSatus);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,18 @@ export class InternetConnectionStatusComponent implements OnInit {
.subscribe((effectiveType: string) => {

this.connectionType = effectiveType;

if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){
if (/\fast-5g|3g|4g/.test(effectiveType)) {
this.toastrService.error('Your request was not completed, you are offline');
this.isFast = false;
}

if (/\fast-5g|3g|4g/.test(effectiveType)){
this.isFast = true;
return
}

if (/\slow-2g|2g/.test(effectiveType)) {
this.toastrService.warning('Caution your connection is slow');
this.isFast = false;
return
}
this.isFast = false;
});
}
}
12 changes: 6 additions & 6 deletions src/app/modules/shared/services/status-network.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ describe('StatusNetworkService', () => {
service = TestBed.inject(StatusNetworkService);
});

it('checkTypeError is error', () => {
it('showTypeToastrServiceAlert is error', () => {
const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: true};
spyOn(toastrServiceStub, 'error');
service.checkTypeError(errorType);
service.showTypeToastrServiceAlert(errorType);
expect(toastrServiceStub.error).toHaveBeenCalled();
});

it('checkTypeError is warning with message', () => {
it('showTypeToastrServiceAlert is warning with message', () => {
const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: false};
spyOn(toastrServiceStub, 'warning');
service.checkTypeError(errorType);
service.showTypeToastrServiceAlert(errorType);
expect(toastrServiceStub.warning).toHaveBeenCalled();
});

it('checkTypeError is warning without message', () => {
it('showTypeToastrServiceAlert is warning without message', () => {
const errorType: ErrorType = {error: catchError, isError: false};
spyOn(toastrServiceStub, 'warning');
service.checkTypeError(errorType);
service.showTypeToastrServiceAlert(errorType);
expect(toastrServiceStub.warning).toHaveBeenCalled();
});
});
30 changes: 17 additions & 13 deletions src/app/modules/shared/services/status-network.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ export class StatusNetworkService {
private toastrService: ToastrService
) { }

checkTypeError(dataError: ErrorType){
const { isError = false, message = 'The server is disconnected', error} = dataError;
showTypeToastrServiceAlert(dataError: ErrorType) {
const { isError = false, message = 'The server is disconnected', error } = dataError;
const effectiveTypenetwork = navigator.connection;
if ((effectiveTypenetwork.effectiveType !== '2g')){
if (!isError){
this.toastrService.warning(message);
}
if (isError){
const errorMessa = error.error && error.error.message ? error.error.message : 'There is an error with the server, your request have not be completed';
this.toastrService.error(errorMessa);
}

if (effectiveTypenetwork.effectiveType === '2g') {
this.toastrService.warning('Your request was not completed, your connection is slow');
return
}
this.toastrService.warning('Your request was not completed, your connection is slow');
}
}

if (!isError) {
this.toastrService.warning(message);
return
}

const errorMessa = (error.error && error.error.message ? error.error.message :
'There was an error in the server, your request was not completed');
this.toastrService.error(errorMessa);

}}
Loading