diff --git a/src/app/components/supplier-table/supplier-table.html b/src/app/components/supplier-table/supplier-table.html
index 1a89523..8c6c89b 100644
--- a/src/app/components/supplier-table/supplier-table.html
+++ b/src/app/components/supplier-table/supplier-table.html
@@ -45,7 +45,7 @@
+ (click)="openEditProductModal(product, supplier.id)">
@@ -81,7 +81,7 @@
diff --git a/src/app/components/supplier-table/supplier-table.ts b/src/app/components/supplier-table/supplier-table.ts
index d95457b..8db396e 100644
--- a/src/app/components/supplier-table/supplier-table.ts
+++ b/src/app/components/supplier-table/supplier-table.ts
@@ -36,6 +36,7 @@ export class SupplierTable implements OnInit {
productModal = viewChild.required
('productModal');
selectedSupplier: GetSupplierDto | null = null;
selectedProduct: GetPriceDto | null = null;
+ selectedProductSupplierId: number | null = null;
async ngOnInit() {
await this.fetchSuppliers();
@@ -82,8 +83,9 @@ export class SupplierTable implements OnInit {
this.supplierModal().showModal();
}
- openEditProductModal(product: GetPriceDto) {
+ openEditProductModal(product: GetPriceDto, supplierId: number) {
this.selectedProduct = { ...product };
+ this.selectedProductSupplierId = supplierId;
this.productModal().showModal();
}
@@ -98,11 +100,14 @@ export class SupplierTable implements OnInit {
async onModalProductOk(
productId: number | undefined,
- supplierId: number | undefined,
+ supplierId: number | null | undefined,
updateProductComponent: PriceForm,
modal: ModalNav
) {
- if (!productId || !supplierId || !this.selectedProduct) return;
+ if (productId == null || supplierId == null || !this.selectedProduct) {
+ this.notificationService.error('Erreur', 'Identifiants produit/fournisseur manquants');
+ return;
+ }
await this.editPrice(productId, supplierId, updateProductComponent);
updateProductComponent.priceForm.reset();
@@ -119,7 +124,6 @@ export class SupplierTable implements OnInit {
this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire');
return;
}
-
try {
const formValue = updateProductComponent.priceForm.getRawValue();
const body = {
@@ -127,9 +131,6 @@ export class SupplierTable implements OnInit {
supplierId,
sellingPrice: Number(formValue.price),
};
-
- console.log('PATCH body =>', body);
-
await firstValueFrom(this.pricesService.patchPriceEndpoint(productId, supplierId, body));
this.notificationService.success('Success', 'Prix modifié');
} catch (e) {