| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import { Injectable } from '@angular/core';
- import { HttpClient, HttpHeaders } from '@angular/common/http';
- import { MatSnackBar } from '@angular/material/snack-bar';
- import { ResponseData } from 'src/app/interfaces/response-data';
- import { map } from 'rxjs';
- import { MCOMORInterface } from '../../../interfaces/mco/mcomor/mcomor-interface';
- import { IAMService } from '../../iam/iam.service';
- import { USERInterface } from 'src/app/interfaces/user-interface';
- import { ENCService } from '../../enc/enc.service';
- @Injectable({
- providedIn: 'root',
- })
- export class MCOMORService {
- private _url = 'https://qasirh.ittec.mx/v1/public/api/MCOMOR';
- jwt = localStorage.getItem('jwt');
- headers = new HttpHeaders({ Authorization: 'Bearer ' + this.jwt });
- usuario_session: USERInterface = {} as USERInterface;
- constructor(private _http: HttpClient, private _snackBar: MatSnackBar, private _encService: ENCService) {}
- ngOnInit() {
- this.usuario_session = JSON.parse(localStorage.getItem('TIMUSERENC')!);
- }
- obtenerOrganigrama() {
- this.ngOnInit();
- return this._http
- .get<ResponseData>(
- `${this._url}/consultar/${ this._encService.desencriptar(this.usuario_session.IDUSUARIO) }/${this.formatoRFC(this.usuario_session.RFCEMPRESA)}`,
- { headers: this.headers }
- )
- .pipe(
- map((data: any) => {
- return data;
- }, (error:any) => {
- if (!error.ok) {
- this.snackAlert('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this.snackAlert(error.error.msg);
- }
- if (error.status == 408) {
- this.snackAlert('Conexion lenta');
- }
- })
- );
- }
- registrarOrganigrama(organigrama: any) {
- return this._http
- .post<ResponseData>(`${this._url}/insertar`, organigrama, {
- headers: this.headers,
- })
- .subscribe(
- (res) => {
- if (!res.error) {
- this.snackAlert('!Registro existoso!');
- } else {
- this.snackAlert(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this.snackAlert('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this.snackAlert(error.error.msg);
- }
- if (error.status == 408) {
- this.snackAlert('Conexion lenta');
- }
- }
- );
- }
- modificarOrganigrama(organigrama: any) {
- return this._http
- .post<ResponseData>(`${this._url}/modificar`, organigrama, {
- headers: this.headers,
- })
- .subscribe(
- (res) => {
- if (!res.error) {
- this.snackAlert('!Modificación existosa!');
- } else {
- this.snackAlert(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this.snackAlert('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this.snackAlert(error.error.msg);
- }
- if (error.status == 408) {
- this.snackAlert('Conexion lenta');
- }
- }
- );
- }
- private formatoRFC(rfc: string){
- let rfc_decoded = window.atob(rfc);
- let rfc_replace = rfc_decoded.replace("|", "/");
- return rfc_replace;
- }
- private snackAlert(mensaje: string) {
- this._snackBar.open(mensaje, 'Cerrar', {
- duration: 4000,
- });
- }
- }
|