import { BehaviorSubject, Observable, Subscription } from 'rxjs'; import { BasketAction } from '../../_models/basket-actions/basket-action'; import { ComparableProduct } from '../../_types/builded/comparable-product'; import { BasketsService } from '../baskets.service'; import { SuppliersService } from '../suppliers.service'; import * as i0 from "@angular/core"; export declare class BasketsSynchronizerService { private basketsService; private supplierService; subscriptions: Subscription[]; mealzActionList: BehaviorSubject; firstRetailerCartChanged: boolean; noSupplier$: BehaviorSubject; private lockWhileConfirming; private lockWhileSynchronizing; /** * Method to be defined through context - Sends both add and remove actions to retailer * Client needs to either define pushProducts or both addProducts and removeProducts */ pushProductsToRetailerCart: (comparableProducts: ComparableProduct[]) => void; /** * Method to be defined through context - Sends add actions to retailer */ addProductsToRetailerCart: (comparableProducts: ComparableProduct[]) => void; /** * Method to be defined through context - Sends remove actions to retailer */ removeProductsFromRetailerCart: (comparableProducts: ComparableProduct[]) => void; constructor(basketsService: BasketsService, supplierService: SuppliersService); private init; pushBasketEntriesToBasket: (entries: any[]) => void; /** ************************************** ACTION LIST MANAGEMENT ************************************** **/ /** * Add a list of basket entries to the action list with the specified action type * @param actions */ addToActionList(actions: BasketAction[]): void; /** * Subscribe to the actions list and execute after 800ms debounce */ listenActionList(): void; sendActionsToRetailerCart(actionsForRetailer: ComparableProduct[]): void; /** * Takes a list of BasketActions and for each action that is not a duplicate (based on the action's id) * it calls the createActionForRetailer() method and adds the observable returned by this method * to the actionsToProcess array. * Then it uses forkJoin to wait for all of the actions to complete before resolving the observable. * The resolved value is an array of ComparableProducts that represent the products and quantities * to be added or removed from the retailer's cart. * @param actions the list of BasketActions to process * @returns an observable that resolves with an array of ComparableProducts */ private createActionsForRetailer; /** * Synchronizes the Mealz basket with the retailer's cart. * This involves checking which products are in both the Mealz basket and the retailer's cart, * and updating the quantities in the Mealz basket to match the quantities in the retailer's cart. * @param retailerBasketProducts the list of products in the retailer's cart */ syncMealzBasketWithRetailerCart(retailerBasketProducts: ComparableProduct[]): void; private mapRetailerCartProducts; /** * Handle a product that is both in the Mealz basket and in the retailer's cart. * This function first updates the Mealz basket entry with the quantity from the retailer's cart. * Then it waits until the Mealz basket entry is not being updated anymore and emits a void value. * This is done to avoid concurrent updates of the Mealz basket entry. * @param product - The product in the retailer's cart to be matched with the Mealz basket entry * @param basketEntry - The Mealz basket entry that is to be updated * @returns An Observable that emits a void value when the Mealz basket entry is updated */ private handleMatchingProduct; /** * Handles a product that is in the Mealz basket but not in the retailer's cart. * This function first removes the Mealz basket entry. * Then it waits until the Mealz basket entry is not being removed anymore and emits a void value. * This is done to avoid concurrent updates of the Mealz basket entry. * @param basketEntry - The Mealz basket entry that is to be removed * @returns An Observable that emits a void value when the Mealz basket entry is removed */ private handleNonMatchingProduct; /** ************************************** RETAILER BASKET PROCESSING ************************************** **/ /** * Updates Mealz basket based on changes in the retailer's cart * @param retailerBasketProducts - Array of products from the retailer's cart */ retailerCartChanged(retailerBasketProducts: ComparableProduct[]): void; /** * Iterates over the products added to the retailer's cart and checks if there are corresponding actions in the list * of current actions. If a match is found, check if the action status is 'SENT_TO_RETAILER', if so, update the action's * status to 'RETAILER_PRODUCT_MATCH', sync the action with the retailer product, update the Mealz basket and remove * the action from the list. * @param addedProducts - Array of products added to the retailer's cart * @param currentActions - Array of current actions */ checkAddActions(addedProducts: ComparableProduct[], currentActions: BasketAction[]): void; /** * Iterates over the products removed from the retailer's cart and checks if there are corresponding actions in the list * of current actions. If a match is found, check if the action status is 'SENT_TO_RETAILER', if so, update the action's * status to 'RETAILER_PRODUCT_MATCH', update the Mealz basket and remove * the action from the list. If no match is found, remove the excess products from the Mealz basket. * @param removedProducts - Array of products removed from the retailer's cart * @param currentActions - Array of current actions */ checkRemoveActions(removedProducts: ComparableProduct[], currentActions: BasketAction[]): void; /** * Iterate over the updated products and check if any of the current actions match them. * If a match is found, check if the action status is 'SENT_TO_RETAILER', if so, update the * action's status to 'RETAILER_PRODUCT_MATCH', sync the action with the retailer product, * update the Mealz basket and remove the action from the list. * If no match is found, remove the excess products from the Mealz basket. * @param updatedProducts - Array of products with updated quantities * @param currentActions - Array of current actions */ checkUpdateActions(updatedProducts: ComparableProduct[], currentActions: BasketAction[]): void; checkActionsToSkip(retailerActions: ComparableProduct[]): ComparableProduct[]; skipRetailerUpdateForAction(action: BasketAction): void; /** * Remove finished actions from the action list based on the given product ID * @param productId - ID of the product to check * @param basketAction - Action associated with the product */ private removeFinishedActionsFromList; private finishAction; /** * Find a product in the Mealz basket and update it based on the retailer's cart * @param product - Product from the retailer's cart to find */ private findAndRemoveExcessProductsInMealzBasket; private findProductInBasketEntries; /** * Update the Mealz basket based on the retailer's cart for the given product * @param product - Product from the retailer's cart * @param found - Corresponding basket entry in the Mealz basket * @param lockWhenSynchronizing - Whether to lock actions process while synchronizing */ private updateMealzBasketFromRetailerBasket; /** ************************************** LIST UTILS TO DISPLAY LOADERS ************************************** **/ private subjectContainsEntryId; hasPendingActions(): Observable; entryWillBeAdded(entryId: string): Observable; entryWillBeUpdated(entryId: string): Observable; /** * Compares two arrays of comparable products and returns an object with three arrays: * - `addedProducts`: products that are present in `t0` but not in `tMinus1` * - `removedProducts`: products that are present in `tMinus1` but not in `t0` * - `updatedProducts`: products that are present in both `tMinus1` and `t0` but have a different quantity in `t0` * compared to `tMinus1`. The `additionalInfos` property of each product in this array will contain the key * `quantityDifference` with the value of `product.quantity - previousProduct.quantity` * * @param tMinus1 the array of products at time `t-1` * @param t0 the array of products at time `t` */ private compareProducts; /** ************************************** EXTERNAL METHODS ************************************** **/ handlePayment(total: number): void; /** * When basketsService.confirming's last emitted value was true and current emitted value is false, * Reset basket-sync */ listenToConfirm(): void; resetMealz(): void; static ɵfac: i0.ɵɵFactoryDef; static ɵprov: i0.ɵɵInjectableDef; } //# sourceMappingURL=baskets-synchronizer.service.d.ts.map