diff --git a/src/app/core/services/product.service.ts b/src/app/core/services/product.service.ts index 04d51f0..681f9fe 100644 --- a/src/app/core/services/product.service.ts +++ b/src/app/core/services/product.service.ts @@ -8,7 +8,6 @@ import { environment } from 'src/environments/environment'; }) export class ProductService { private apiUrl = `${environment.apiUrl}/api/products`; - private apiUrlUpdate = `${environment.apiUrl}/api/`; constructor(private http: HttpClient) { } @@ -23,13 +22,25 @@ export class ProductService { updateProducts(formData: any): Observable { + const {id}= formData const token = localStorage.getItem('token'); const headers = new HttpHeaders({ Authorization: `Bearer ${token}`, }); - return this.http.get(this.apiUrl, { headers }); + return this.http.put(`${this.apiUrl}/${id}`, formData, { headers }); } + + deleteProducts(formData: any): Observable { + const { id } = formData + const token = localStorage.getItem('token'); + const headers = new HttpHeaders({ + Authorization: `Bearer ${token}`, + }); + + return this.http.delete(`${this.apiUrl}/${id}`, { headers }); + } + // Método para enviar os dados do produto para a API sendDataToApi(data: any): Observable { console.log("🚀 ~ ProductService ~ sendDataToApi ~ data:", data) diff --git a/src/app/modules/products/pages/add-product/add-product.component.ts b/src/app/modules/products/pages/add-product/add-product.component.ts index 16aada9..e3adc20 100644 --- a/src/app/modules/products/pages/add-product/add-product.component.ts +++ b/src/app/modules/products/pages/add-product/add-product.component.ts @@ -334,8 +334,9 @@ export class AddProductComponent implements OnInit { formData.id = this.product.id; // Inclui o ID do produto a ser atualizado this.productService.updateProducts(formData).subscribe( (response) => { - const index = this.products.findIndex(p => p.id === formData.id); - if (index !== -1) this.products[index] = response; + console.log(response) + // const index = this.products.findIndex(p => p.id === formData.id); + // if (index !== -1) this.products[index] = response; this.showSuccess('Product updated successfully'); this.closeDialog(); },