mesmre.service.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { HttpClient, HttpHeaders } from '@angular/common/http';
  2. import { Injectable } from '@angular/core';
  3. import { MatSnackBar } from '@angular/material/snack-bar';
  4. import { map } from 'rxjs';
  5. import { MESMREInterface } from 'src/app/interfaces/mes/mesmre/mesmre-interface';
  6. import { ResponseData } from 'src/app/interfaces/response-data';
  7. import { USERInterface } from 'src/app/interfaces/user-interface';
  8. import { ENCService } from '../../enc/enc.service';
  9. @Injectable({
  10. providedIn: 'root',
  11. })
  12. export class MESMREService {
  13. private _url = 'https://qasirh.ittec.mx/v1/public/api/MESMRE';
  14. private _url_empleados =
  15. 'https://qasirh.ittec.mx/v1/public/api/MCOMAU';
  16. //usuario: USERInterface = this._iamService.usuario;
  17. usuario_session: USERInterface = {} as USERInterface;
  18. jwt: any = '';
  19. header: HttpHeaders;
  20. constructor(
  21. private http: HttpClient,
  22. private _snackBar: MatSnackBar,
  23. private _encService: ENCService
  24. ) {
  25. this.jwt = localStorage.getItem('jwt');
  26. this.header = new HttpHeaders().set('Authorization', 'Bearer ' + this.jwt);
  27. }
  28. ngOnInit() {
  29. this.usuario_session = JSON.parse(localStorage.getItem('TIMUSERENC')!);
  30. }
  31. consultar() {
  32. this.ngOnInit();
  33. return this.http.get<MESMREInterface>(
  34. `${this._url}/consultar/${this._encService.desencriptar(
  35. this.usuario_session.IDUSUARIO
  36. )}/${this.formatoRFC(this.usuario_session.RFCEMPRESA)}}`,
  37. { headers: this.header }
  38. ).pipe(map(data => data));
  39. }
  40. consultarUsuario(id: string) {
  41. return this.http.get<MESMREInterface>(
  42. `${this._url}/consultar/${id}/${this.formatoRFC(this.usuario_session.RFCEMPRESA)}}`,
  43. { headers: this.header }
  44. ).pipe(map(data => data));
  45. }
  46. consultarTodos(): any {
  47. return this.http.get<ResponseData>(
  48. `${this._url}/consultar/todos/${this._encService.desencriptar(
  49. this.usuario_session.PERFIL
  50. )}/${this._encService.desencriptar(this.usuario_session.IDUSUARIO)}/${this.formatoRFC(this.usuario_session.RFCEMPRESA)}}`,
  51. { headers: this.header }
  52. ).pipe(map(data => data));
  53. }
  54. consultarEmpleados(): any {
  55. return this.http.get<ResponseData>(
  56. `${
  57. this._url_empleados
  58. }/consultar/empleados/${this._encService.desencriptar(
  59. this.usuario_session.IDUSUARIO
  60. )}/${this.formatoRFC(this.usuario_session.RFCEMPRESA)}}`,
  61. { headers: this.header }
  62. ).pipe(map(data => data));
  63. }
  64. private formatoRFC(rfc: string){
  65. let rfc_decoded = window.atob(rfc);
  66. let rfc_replace = rfc_decoded.replace("|", "/");
  67. return rfc_replace;
  68. }
  69. }