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
feat: TTA-115 implement notification when the endpoint fails for a sl…
…ow connection
  • Loading branch information
Abigail Cabascango committed Sep 12, 2022
commit da0522a8500fa738b7581811236756b6f00e2930
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
import * as actions from './activity-management.actions';
import { Activity, ActivityStatus } from './../../shared/models/activity.model';
import { ActivityService } from './../services/activity.service';
import { StatusNetworkService } from '../../shared/services/status-network.service';

@Injectable()
export class ActivityEffects {
constructor(
private actions$: Actions,
private activityService: ActivityService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -27,7 +29,7 @@ export class ActivityEffects {
return new actions.LoadActivitiesSuccess(activities);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.LoadActivitiesFail(error));
})
)
Expand All @@ -45,7 +47,7 @@ export class ActivityEffects {
return new actions.CreateActivitySuccess(activityData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.CreateActivityFail(error));
})
)
Expand All @@ -66,7 +68,7 @@ export class ActivityEffects {
return new actions.ArchiveActivitySuccess(activity);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.ArchiveActivityFail(error));
})
)
Expand All @@ -84,7 +86,7 @@ export class ActivityEffects {
return new actions.UpdateActivitySuccess(activityData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.UpdateActivityFail(error));
})
)
Expand All @@ -106,7 +108,7 @@ export class ActivityEffects {
return new actions.UnarchiveActivitySuccess(activityData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.UnarchiveActivityFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export class ProjectTypeService {

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

createProjectType(projectTypeData): Observable<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import * as actions from './project-type.actions';
import { ProjectType } from '../../../../shared/models';
import { ProjectTypeService } from '../services/project-type.service';
import { ToastrService } from 'ngx-toastr';
import { StatusNetworkService } from '../../../../shared/services/status-network.service';

@Injectable()
export class ProjectTypeEffects {
constructor(
private actions$: Actions,
private projectTypeService: ProjectTypeService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -27,7 +29,7 @@ export class ProjectTypeEffects {
return new actions.LoadProjectTypesSuccess(projectTypes);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.LoadProjectTypesFail(error));
})
)
Expand All @@ -45,7 +47,7 @@ export class ProjectTypeEffects {
return new actions.CreateProjectTypeSuccess(projectTypeData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.CreateProjectTypeFail(error));
})
)
Expand All @@ -63,7 +65,7 @@ export class ProjectTypeEffects {
return new actions.DeleteProjectTypeSuccess(protectTypeId);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.DeleteProjectTypeFail(error));
})
)
Expand All @@ -81,7 +83,7 @@ export class ProjectTypeEffects {
return new actions.UpdateProjectTypeSuccess(projectTypeData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.UpdateProjectTypeFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { ProjectService } from '../services/project.service';
import * as actions from './project.actions';
import { ToastrService } from 'ngx-toastr';
import { Status } from 'src/app/modules/shared/models';
import { StatusNetworkService } from '../../../../../shared/services/status-network.service';

@Injectable()
export class ProjectEffects {
constructor(
private actions$: Actions,
private projectService: ProjectService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -26,7 +28,7 @@ export class ProjectEffects {
return new actions.LoadProjectsSuccess(projects);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.LoadProjectsFail(error));
})
)
Expand All @@ -42,7 +44,7 @@ export class ProjectEffects {
return new actions.LoadCustomerProjectsSuccess(project);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.LoadCustomerProjectsFail(error));
})
)
Expand All @@ -58,7 +60,7 @@ export class ProjectEffects {
return new actions.LoadRecentProjectsSuccess(projects);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.LoadRecentProjectsFail(error));
})
)
Expand All @@ -76,7 +78,7 @@ export class ProjectEffects {
return new actions.CreateProjectSuccess(projectData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.CreateProjectFail(error));
})
)
Expand All @@ -94,7 +96,7 @@ export class ProjectEffects {
return new actions.UpdateProjectSuccess(projectData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.UpdateProjectFail(error));
})
)
Expand All @@ -112,7 +114,7 @@ export class ProjectEffects {
return new actions.DeleteProjectSuccess(projectId);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.DeleteProjectFail(error));
})
)
Expand All @@ -133,7 +135,7 @@ export class ProjectEffects {
return new actions.UnarchiveProjectSuccess(projectData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.UnarchiveProjectFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr';
import { CustomerService } from '../services/customer.service';
import * as actions from './customer-management.actions';
import { Status } from '../../shared/models/customer.model';
import { StatusNetworkService } from '../../shared/services/status-network.service';

@Injectable()
export class CustomerEffects {
constructor(
private actions$: Actions,
private customerService: CustomerService,
private toastrService: ToastrService
private toastrService: ToastrService,
private statusNetworkService: StatusNetworkService
) { }

@Effect()
Expand All @@ -27,7 +29,7 @@ export class CustomerEffects {
return new actions.LoadCustomersSuccess(customers);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.LoadCustomersFail(error));
}
)
Expand All @@ -46,7 +48,7 @@ export class CustomerEffects {
return new actions.CreateCustomerSuccess(customerData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.CreateCustomerFail(error));
})
)
Expand All @@ -64,7 +66,7 @@ export class CustomerEffects {
return new actions.DeleteCustomerSuccesss(customerId);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.DeleteCustomerFail(error));
})
)
Expand All @@ -82,7 +84,7 @@ export class CustomerEffects {
return new actions.UpdateCustomerSuccess(customerData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.UpdateCustomerFail(error));
})
)
Expand All @@ -104,7 +106,7 @@ export class CustomerEffects {
return new actions.UpdateCustomerSuccess(customerData);
}),
catchError((error) => {
this.toastrService.error(error.error.message);
this.statusNetworkService.checkTypeError({error, isError: true});
return of(new actions.UpdateCustomerFail(error));
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ export class InternetConnectionStatusComponent implements OnInit {
});

ngOnInit(){
// $scope, $http
// $scope.isLoading = function () {
// return $http.pendingRequests.length !== 0;
// };
const connection = navigator.connection;
console.log('navigator component', connection);
if (!connection || !connection.effectiveType) {
Expand All @@ -79,10 +75,9 @@ export class InternetConnectionStatusComponent implements OnInit {
this.toastrService.warning('Caution your connection is slow');
this.isFast = false;
} else {
this.toastrService.error('You are offline');
this.toastrService.error('Your request was not completed, you are offline');
this.isFast = false;
}
});
}

}
16 changes: 16 additions & 0 deletions src/app/modules/shared/services/status-network.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { StatusNetworkService } from './status-network.service';

describe('StatusNetworkService', () => {
let service: StatusNetworkService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(StatusNetworkService);
});

fit('should be created', () => {
expect(service).toBeTruthy();
});
});
33 changes: 33 additions & 0 deletions src/app/modules/shared/services/status-network.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';
import { ToastrService } from 'ngx-toastr';

export interface ErrorType {
error: any;
message?: string;
isError?: boolean;
}

@Injectable({
providedIn: 'root'
})
export class StatusNetworkService {

constructor(
private toastrService: ToastrService
) { }

checkTypeError(dataError: ErrorType){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le ponemos de nombre swhowMessage?

const { isError = false, message = 'The server is disconnected', error} = dataError;
const effectiveTypenetwork = navigator.connection;
if(effectiveTypenetwork.effectiveType === '2g'){
this.toastrService.warning('Your request was not completed, your connection is slow');
}else{
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);
}else{
this.toastrService.warning(message);
}
}
}
}
Loading