Commit 8c519ea534e8f91e41561f2d0de96f7f2991df39
1 parent
229356bd3d
Exists in
master
and in
1 other branch
Agregado servicio para borrar imagenes.
Showing
1 changed file
with
5 additions
and
1 deletions
Show diff stats
src/app/services/producto.service.ts
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core'; |
2 | import { HttpClient } from '@angular/common/http'; | 2 | import { HttpClient } from '@angular/common/http'; |
3 | import { Observable } from 'rxjs'; | 3 | import { Observable } from 'rxjs'; |
4 | import { appSettings } from 'src/etc/AppSettings'; | 4 | import { appSettings } from 'src/etc/AppSettings'; |
5 | import { Producto } from '../wrappers/producto'; | 5 | import { Producto } from '../wrappers/producto'; |
6 | 6 | ||
7 | @Injectable({ | 7 | @Injectable({ |
8 | providedIn: 'root' | 8 | providedIn: 'root' |
9 | }) | 9 | }) |
10 | export class ProductoService { | 10 | export class ProductoService { |
11 | 11 | ||
12 | productos: Producto[] = []; | 12 | productos: Producto[] = []; |
13 | productoAcargar: Producto; | 13 | productoAcargar: Producto; |
14 | promoAcargar: Producto; | 14 | promoAcargar: Producto; |
15 | mostrar: string; | 15 | mostrar: string; |
16 | 16 | ||
17 | constructor(private http: HttpClient) { } | 17 | constructor(private http: HttpClient) { } |
18 | 18 | ||
19 | getProductoById(id): Observable<any> { | 19 | getProductoById(id): Observable<any> { |
20 | 20 | ||
21 | return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); | 21 | return this.http.get(`${appSettings.apiUrl}/articulos/${id}`); |
22 | } | 22 | } |
23 | 23 | ||
24 | getAll(): Observable<any> { | 24 | getAll(): Observable<any> { |
25 | 25 | ||
26 | return this.http.get(`${appSettings.apiUrl}/articulos`); | 26 | return this.http.get(`${appSettings.apiUrl}/articulos`); |
27 | } | 27 | } |
28 | 28 | ||
29 | setProductos(producto: Producto) { | 29 | setProductos(producto: Producto) { |
30 | 30 | ||
31 | for (let i = 0; i < this.productos.length; i++) { | 31 | for (let i = 0; i < this.productos.length; i++) { |
32 | 32 | ||
33 | if (this.productos[i].id === producto.id) { | 33 | if (this.productos[i].id === producto.id) { |
34 | 34 | ||
35 | if (producto.PRO) { | 35 | if (producto.PRO) { |
36 | if (this.promosIdenticas(this.productos[i], producto)) { | 36 | if (this.promosIdenticas(this.productos[i], producto)) { |
37 | this.productos[i].cantidad++; | 37 | this.productos[i].cantidad++; |
38 | return; | 38 | return; |
39 | } else { | 39 | } else { |
40 | break; | 40 | break; |
41 | } | 41 | } |
42 | } | 42 | } |
43 | this.productos[i].cantidad++; | 43 | this.productos[i].cantidad++; |
44 | return; | 44 | return; |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | this.productos.push(producto); | 48 | this.productos.push(producto); |
49 | } | 49 | } |
50 | 50 | ||
51 | getPromocionByCodigos(sector, codigo): Observable<any> { | 51 | getPromocionByCodigos(sector, codigo): Observable<any> { |
52 | 52 | ||
53 | var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; | 53 | var url = `${appSettings.apiUrl}/promociones/by-codigos/${sector}/${codigo}`; |
54 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; | 54 | // var url = `${appSettings.apiUrl}/promociones/by-codigos/${2}/${7}`; |
55 | return this.http.get(url); | 55 | return this.http.get(url); |
56 | } | 56 | } |
57 | 57 | ||
58 | getPromociones(sector, codigo): Observable<any> { | 58 | getPromociones(sector, codigo): Observable<any> { |
59 | 59 | ||
60 | var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; | 60 | var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${sector}/${codigo}`; |
61 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; | 61 | // var url = `${appSettings.apiUrl}/promociones/incluir-articulo/${2}/${1306}`; |
62 | return this.http.get(url); | 62 | return this.http.get(url); |
63 | } | 63 | } |
64 | 64 | ||
65 | getPromocionSinonimos(sector, codigo): Observable<any> { | 65 | getPromocionSinonimos(sector, codigo): Observable<any> { |
66 | 66 | ||
67 | var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; | 67 | var url = `${appSettings.apiUrl}/sinonimos/promo/${sector}/${codigo}`; |
68 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; | 68 | // var url = `${appSettings.apiUrl}/sinonimos/promo/${2}/${7}`; |
69 | return this.http.get(url); | 69 | return this.http.get(url); |
70 | } | 70 | } |
71 | 71 | ||
72 | updateImages(body): Observable<any> { | 72 | saveInBase(body): Observable<any> { |
73 | return this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, body); | 73 | return this.http.post(`${appSettings.apiUrl}/imagenes/guardar`, body); |
74 | } | 74 | } |
75 | 75 | ||
76 | deleteImage(body) : Observable<any>{ | ||
77 | return this.http.post(`${appSettings.apiUrl}/imagen/borrar`, body); | ||
78 | } | ||
79 | |||
76 | getCategorias() { | 80 | getCategorias() { |
77 | return this.http.get(`${appSettings.apiUrl}/categorias`); | 81 | return this.http.get(`${appSettings.apiUrl}/categorias`); |
78 | } | 82 | } |
79 | 83 | ||
80 | pagar() { | 84 | pagar() { |
81 | return this.http.post(`${appSettings.apiUrl}/comprobante/guardar`, { | 85 | return this.http.post(`${appSettings.apiUrl}/comprobante/guardar`, { |
82 | productos: this.productos | 86 | productos: this.productos |
83 | }); | 87 | }); |
84 | } | 88 | } |
85 | 89 | ||
86 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { | 90 | private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { |
87 | 91 | ||
88 | var sonIdenticas = true; | 92 | var sonIdenticas = true; |
89 | var productosPromoCarrito = promoEnCarrito.productos; | 93 | var productosPromoCarrito = promoEnCarrito.productos; |
90 | var productosPromoAcargar = promo.productos; | 94 | var productosPromoAcargar = promo.productos; |
91 | 95 | ||
92 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { | 96 | if (productosPromoCarrito.length !== productosPromoAcargar.length) { |
93 | return false; | 97 | return false; |
94 | } | 98 | } |
95 | 99 | ||
96 | for (let i = 0; i < productosPromoCarrito.length; i++) { | 100 | for (let i = 0; i < productosPromoCarrito.length; i++) { |
97 | 101 | ||
98 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { | 102 | if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { |
99 | return false; | 103 | return false; |
100 | } | 104 | } |
101 | } | 105 | } |
102 | 106 | ||
103 | return sonIdenticas; | 107 | return sonIdenticas; |
104 | } | 108 | } |
105 | 109 | ||
106 | } | 110 | } |
107 | 111 |