diff --git a/src/app/components/stock-table/stock-table.html b/src/app/components/stock-table/stock-table.html
index 29daffa..b2f26e2 100644
--- a/src/app/components/stock-table/stock-table.html
+++ b/src/app/components/stock-table/stock-table.html
@@ -43,9 +43,8 @@
{{ product.caliber }} |
{{ product.weight }} |
{{ product.duration }} |
- Quantité totale ??? |
+ {{ product.totalQuantity }} |
{{ product.minimalQuantity }} |
-
diff --git a/src/app/components/stock-table/stock-table.ts b/src/app/components/stock-table/stock-table.ts
index 5550d53..c99f6de 100644
--- a/src/app/components/stock-table/stock-table.ts
+++ b/src/app/components/stock-table/stock-table.ts
@@ -6,10 +6,14 @@ import {StockForm} from "../stock-form/stock-form";
import {NzDividerComponent} from "ng-zorro-antd/divider";
import {FormsModule} from "@angular/forms";
import {NzCheckboxComponent} from "ng-zorro-antd/checkbox";
-import {GetProductDto, ProductsService} from "../../services/api";
+import {GetProductDto, ProductsService, WarehouseproductsService} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs";
+interface ProductWithQuantity extends GetProductDto {
+ totalQuantity?: number;
+}
+
@Component({
selector: 'app-stock-table',
imports: [
@@ -28,8 +32,9 @@ import {firstValueFrom} from "rxjs";
export class StockTable implements OnInit {
private productsService = inject(ProductsService);
+ private wareHousseProductsService = inject(WarehouseproductsService)
private notificationService = inject(NzNotificationService)
- products = signal ([]);
+ products = signal([]);
productsLoading = signal(false);
updateProduct = viewChild.required('stockForm');
modal = viewChild.required('modalNav');
@@ -84,19 +89,43 @@ export class StockTable implements OnInit {
await this.fetchProducts();
}
- async fetchProducts() {
- this.productsLoading.set(true)
-
+ async fetchTotalQuantity(product: ProductWithQuantity) {
try {
- const products = await firstValueFrom(this.productsService.getAllProductsEndpoint())
- this.products.set(products);
+ const res = await firstValueFrom(
+ this.wareHousseProductsService.getTotalQuantityEndpoint(product.id)
+ );
+ product.totalQuantity = res.totalQuantity;
+ } catch (e) {
+ product.totalQuantity = 0;
+ this.notificationService.error(
+ 'Erreur',
+ `Impossible de récupérer la quantité pour le produit n°${product.id}`
+ );
+ }
+ }
+
+ async fetchProducts() {
+ this.productsLoading.set(true);
+ try {
+ const products = await firstValueFrom(this.productsService.getAllProductsEndpoint());
+
+ // transforme chaque produit en ProductWithQuantity
+ const productsWithQuantity: ProductWithQuantity[] = products.map(p => ({ ...p }));
+
+ this.products.set(productsWithQuantity);
+
+ // récupérer la quantité pour chaque produit en parallèle
+ await Promise.all(productsWithQuantity.map(p => this.fetchTotalQuantity(p)));
+
+ // déclencher la mise à jour du signal
+ this.products.set([...productsWithQuantity]);
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur de communication avec l\'API'
- )
+ );
}
- this.productsLoading.set(false)
+ this.productsLoading.set(false);
}
async delete(productId:number) {
|