Ver Fonte

Modicaciones de services

JeanBenitez há 3 anos atrás
pai
commit
2488960610

+ 35 - 0
sistema-mantenimiento-front/src/app/services/generic/generic.service.ts

@@ -0,0 +1,35 @@
+import { Injectable } from '@angular/core';
+import { HttpClient, HttpHeaders } from '@angular/common/http';
+import { map, Observable } from 'rxjs';
+
+@Injectable({
+  providedIn: 'root'
+})
+export class GenericService {
+
+  private _url:string = "http://192.168.100.154:8000/api/generic/";
+  private _token:string = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSJ9.eyJpc3MiOiJqb3NlLmJAaXR0ZWMubXgiLCJhdWQiOiJkb21pbmlvLnN5cC5teCIsImlhdCI6MTY0NzYxMjc0NCwiY2FkIjoxNjQ3Njk5MTQ0fQ.BkpH8BMrx0hExtdU0EsNGxQxcbx_RqvTpGq12DqfbS0IEej5enf6V6q2DbqPsueK_0DMR_CWU9kMMYQCN2jrCg';
+  constructor(private http: HttpClient) { }
+
+  public getDataTable(data: any){
+    return this.getQuery(`consulta-tabla/${data}`).pipe(map((data: any) => data));
+  }
+
+  private getQuery(query: string){
+    const URL = `${this._url}${query}`;
+    return this.http.get(URL, {
+      headers: new HttpHeaders({
+        Authorization: this._token
+      })
+    });
+  }
+
+  private postQuery(query: string, body: any){
+    const URL = `${this._url}${query}`;
+    return this.http.post(URL, body, {
+      headers: new HttpHeaders({
+        Authorization: this._token
+      })
+    });
+  }
+}

+ 4 - 0
sistema-mantenimiento-front/src/app/services/getb/getbme/getbme.service.ts

@@ -19,6 +19,10 @@ export class GetbmeService {
     return this.getQuery("consulta/" + data).pipe(map((data: any) => data))
   }
 
+  public getMenuByForm(data: any) {
+    return this.getQuery("consulta-form/" + data).pipe(map((data: any) => data))
+  }
+
   public postMenu(data: any) {
     const formData = new FormData()
     formData.append('img_menu', data.img_menu)

+ 4 - 0
sistema-mantenimiento-front/src/app/services/getb/getbsm/getbsm.service.ts

@@ -20,6 +20,10 @@ export class GETBSMService {
   public getOneSubmodule(data: any) {
     return this.getQuery("consulta/" + data).pipe(map((data: any) => data))
   }
+  
+  public getSubmoduleByForm(data: any) {
+    return this.getQuery("consulta-form/" + data).pipe(map((data: any) => data))
+  }
 
   public postSubmodules(data: any) {
     return this.postQuery("registra", data).pipe(map((data: any) => data))

+ 16 - 0
sistema-mantenimiento-front/src/app/services/resources/resources.service.spec.ts

@@ -0,0 +1,16 @@
+import { TestBed } from '@angular/core/testing';
+
+import { ResourcesService } from './resources.service';
+
+describe('ResourcesService', () => {
+  let service: ResourcesService;
+
+  beforeEach(() => {
+    TestBed.configureTestingModule({});
+    service = TestBed.inject(ResourcesService);
+  });
+
+  it('should be created', () => {
+    expect(service).toBeTruthy();
+  });
+});

+ 44 - 0
sistema-mantenimiento-front/src/app/services/resources/resources.service.ts

@@ -0,0 +1,44 @@
+import { Injectable } from '@angular/core';
+import { MatSnackBar } from '@angular/material/snack-bar';
+
+@Injectable({
+  providedIn: 'root'
+})
+export class ResourcesService {
+
+  constructor(private _MatSnackBar: MatSnackBar) { }
+
+  public checkErrors(error: any) {
+    console.log(error);
+    
+    if (!error.ok) {
+      this.openSnackBar('Ocurrió un error inesperado');
+    }
+    if (error.error.msg != undefined) {
+      this.openSnackBar(error.error.msg);
+    }
+    if (error.status == 408) {
+      this.openSnackBar('Conexion lenta');
+    }
+  }
+
+  public checkRegister(respuesta: ResponseData) {
+    if (!respuesta.error) {
+      this.openSnackBar('¡Registro exitoso!');
+    } else {
+      this.openSnackBar(respuesta.msg);
+    }
+  }
+
+  public openSnackBar(message: string, action: string = "Cerrar", timer: number = 7000) {
+    this._MatSnackBar.open(message, action, {
+      duration: timer
+    });
+  }
+}
+
+export interface ResponseData {
+  error: Boolean,
+  msg: string,
+  response: any[]
+}