pages.service.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3. import { SharedService } from './shared.service';
  4. import { ToastrService } from 'ngx-toastr';
  5. import { Location } from '@angular/common';
  6. @Injectable({
  7. providedIn: 'root'
  8. })
  9. export class PagesService {
  10. constructor(
  11. private http: HttpClient,
  12. private auth: SharedService,
  13. private toster: ToastrService,
  14. private location: Location,
  15. ) { }
  16. getListData(currentPage: number ,perPage: number, type: any, pageName){
  17. if(pageName == 'system-admins'){
  18. console.log(this.auth.pathApi + '/users_list/' + currentPage+ '/' + '/' + perPage+ '/' + type );
  19. return this.http.get(this.auth.pathApi + '/users_list/' + currentPage+ '/' + perPage+ '/' + type );
  20. }else if(pageName == 'customers'){
  21. console.log(this.auth.pathApi + '/companies_list/' + currentPage+ '/' + '/' + perPage+ '/' + type );
  22. return this.http.get(this.auth.pathApi + '/companies_list/' + currentPage+ '/' + perPage+ '/' + type );
  23. }
  24. }
  25. addItem(data, pageName){
  26. if(pageName == 'system-admins')
  27. {
  28. return this.http.post(this.auth.pathApi + '/register_new_user', data);
  29. }
  30. }
  31. //edit event
  32. editItem(editId,dataEdit,pageName){
  33. const editData = dataEdit;
  34. console.log(editId);
  35. editData['id'] = editId;
  36. console.log(dataEdit);
  37. if(pageName == 'system-admins'){
  38. return this.http.post(this.auth.pathApi + '/edit_current_user' ,editData);
  39. }
  40. }
  41. getItemData(pageId: number, pageName: String)
  42. {
  43. console.log('pageId', pageId);
  44. if(pageName == 'system-admins')
  45. return this.http.get(this.auth.pathApi + '/get_user_by_id/' + pageId);
  46. }
  47. //previous back locarion
  48. perviousLocation() {
  49. this.location.back();
  50. }
  51. //delete event
  52. deleteItem(dataIds, pageName) {
  53. console.log(dataIds);
  54. console.log(pageName);
  55. console.log(this.auth.pathApi+ '/delete_current_users');
  56. if(pageName == 'system-admins') {
  57. return this.http.post(this.auth.pathApi+ '/delete_current_users', {'users_id':dataIds});
  58. }else if (pageName == 'customers' ) {
  59. }
  60. }
  61. }