Skip to content
Snippets Groups Projects
Commit 58c03bad authored by paborte's avatar paborte
Browse files

Delegada funcionalidad de obtencion de referencias a imagenes en el storage a el databaseService

parent 231135d8
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import { Producto } from 'src/app/shared/interfaces/producto.model';
import { AppRoutingModule } from 'src/app/app-routing.module';
import { Router } from '@angular/router';
import { CestaCompraService } from 'src/app/shared/services/cesta-compra.service';
import { DatabaseService } from 'src/app/shared/services/database.service';
@Component({
selector: 'app-item-cesta',
......@@ -17,14 +18,15 @@ export class ItemCestaComponent implements OnInit {
botonCambiarUnidades: boolean = false;
nuevasUnidades: number = 0;
constructor(
private storage: AngularFireStorage,
private databaseService: DatabaseService,
private router: Router,
private cestaService: CestaCompraService
) {}
ngOnInit(): void {
const ref = this.storage.ref(this.entradaCesta.producto.imagenIconoPath);
this.imagen = ref.getDownloadURL();
this.imagen = this.databaseService.getDownloadURLFromStorage(
this.entradaCesta.producto.imagenIconoPath
);
this.rutaProducto =
'/tienda/producto' + this.entradaCesta.producto.productoID;
......
......@@ -43,7 +43,6 @@ export class PedidoItemComponent implements OnInit {
}
getImage(imagePath: string) {
const ref = this.storage.ref(imagePath);
return ref.getDownloadURL();
return this.databaseService.getDownloadURLFromStorage(imagePath);
}
}
......@@ -5,6 +5,7 @@ import {
AngularFireObject,
} from '@angular/fire/compat/database';
import { AngularFirestore, Query } from '@angular/fire/compat/firestore';
import { AngularFireStorage } from '@angular/fire/compat/storage';
import { Router } from '@angular/router';
import { BehaviorSubject, from, Observable, take, tap } from 'rxjs';
......@@ -27,7 +28,8 @@ export class DatabaseService {
constructor(
private db: AngularFireDatabase,
private angularFirestore: AngularFirestore,
private router: Router
private router: Router,
private storage: AngularFireStorage
) {}
createNewUserInDatabase(user: Usuario, uid: string) {
......@@ -61,6 +63,11 @@ export class DatabaseService {
return from(updatePromise);
}
getDownloadURLFromStorage(imagePath: string) {
const ref = this.storage.ref(imagePath);
return ref.getDownloadURL();
}
getUserFromDatabase(uid: string): Observable<any> {
return this.angularFirestore.collection('users').doc(uid).valueChanges();
}
......
......@@ -3,6 +3,7 @@ import { Observable, Subscription } from 'rxjs';
import { Producto } from 'src/app/shared/interfaces/producto.model';
import { AngularFireStorage } from '@angular/fire/compat/storage';
import { CestaCompraService } from 'src/app/shared/services/cesta-compra.service';
import { DatabaseService } from 'src/app/shared/services/database.service';
@Component({
selector: 'app-card-producto',
templateUrl: './card-producto.component.html',
......@@ -17,13 +18,14 @@ export class CardProductoComponent implements OnInit {
cestaSubscription: Subscription;
constructor(
private storage: AngularFireStorage,
private databaseService: DatabaseService,
private cestaService: CestaCompraService
) {}
ngOnInit(): void {
const ref = this.storage.ref(this.producto.imagenIconoPath);
this.imagen = ref.getDownloadURL();
this.imagen = this.databaseService.getDownloadURLFromStorage(
this.producto.imagenIconoPath
);
}
addCesta() {
this.cestaService.addProducto(this.producto, 1);
......
......@@ -45,8 +45,7 @@ export class ProductoComponent implements OnInit, OnDestroy {
});
}
getImage(imagePath: string) {
const ref = this.storage.ref(imagePath);
return ref.getDownloadURL();
return this.databaseService.getDownloadURLFromStorage(imagePath);
}
addCesta() {
this.cestaService.addProducto(this.producto, this.cantidadAIncluirEnCesta);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment