Skip to content

Commit

Permalink
Página ver lista - Lista de productos
Browse files Browse the repository at this point in the history
- Implementado nuevo servicio para desmarcar todos los productos. Ya que solo estaba desmarcando los productos visibles.
  • Loading branch information
nmarulo committed Dec 11, 2024
1 parent ce764a6 commit eca56b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/app/models/products-selected-req.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ProductsSelectedReq {
action: 'SELECT' | 'DESELECT';
}


Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
SelectedProductsComponent
} from '@app/modules/shopping-list/layout/shopping-list/selected-products/selected-products.component';
import {FindByIdProductListReq} from '@app/models/find-by-id-product-list-req';
import {ProductsSelectedReq} from '@app/models/products-selected-req';

@Component({
selector: 'app-shopping-list',
Expand Down Expand Up @@ -222,6 +223,9 @@ export class ShoppingListComponent {
}

deselectAllProductsEvent() {
const request: ProductsSelectedReq = {
action: 'DESELECT'
};
const selectedProducts: ProductUpdateShoppingListReq[] = this.shoppingListRes()
.productList
.content
Expand All @@ -233,10 +237,17 @@ export class ShoppingListComponent {
}));

this.removeAllProducts(selectedProducts.map(product => product.productId));
this.updateProducts(selectedProducts);
this.updateProductsView(selectedProducts);
this.shoppingListsService.updateSelectedProducts(this.shoppingListRes().id, request)
.subscribe();
}

updateProducts(productsReq: ProductUpdateShoppingListReq[]) {
this.updateProductsView(productsReq);
this.updateShoppingList(productsReq);
}

private updateProductsView(productsReq: ProductUpdateShoppingListReq[]) {
this.shoppingListRes.update(value => {
const products = value.productList
.content
Expand Down Expand Up @@ -269,8 +280,6 @@ export class ShoppingListComponent {
}
};
});

this.updateShoppingList(productsReq);
}

removeAllProducts(productsId: number[]) {
Expand Down
4 changes: 4 additions & 0 deletions src/app/services/pages/shopping-lists.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {SaveShoppingListRes} from '../../models/save-shopping-list-res';
import {PagingAndSortingReq} from '@app/models/paging-and-sorting-req';
import {FindByIdProductListReq} from '@app/models/find-by-id-product-list-req';
import {FindByIdProductListRes} from '@app/models/find-by-id-product-list-res';
import {ProductsSelectedReq} from '@app/models/products-selected-req';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -58,4 +59,7 @@ export class ShoppingListsService {
});
}

updateSelectedProducts(id: number, request: ProductsSelectedReq) {
return this.httpClient.put<UpdateShoppingListRes>(`${this._shoppingListsURI}/${id}/products-selected`, request);
}
}

0 comments on commit eca56b1

Please sign in to comment.