import { HttpClient } from '@angular/common/http'; import { EventEmitter } from '@angular/core'; import { Service } from 'miam-jsonapi'; import { BehaviorSubject, Observable } from 'rxjs'; import { Basket, BasketEntry, BasketPreviewLine, Ingredient, Item } from '../_models'; import { BasketStats } from '../_types/basket-stats'; import { ComparableProduct } from '../_types/builded/comparable-product'; import { EventTrace } from '../_types/event-trace'; import { AnalyticsService } from './analytics.service'; import { BasketEntriesService } from './basket-entries.service'; import { IgnoredIngredientsService } from './ignored-ingredients.service'; import { MenusService } from './menus.service'; import { PointOfSalesService } from './point-of-sales.service'; import { PriceService } from './price.service'; import { RecipesService } from './recipes.service'; import { StatesService } from './states.service'; import { ToasterService } from './toaster.service'; import { UserService } from './user.service'; import * as i0 from "@angular/core"; export declare const BASKET_SPARSE_FIELDS: { baskets: string[]; }; export declare class BasketsService extends Service { private http; private basketEntriesService; private posService; private recipesService; private analyticsService; private usersService; private toasterService; private ignoredBasketsService; private statesService; private priceService; private menusService; static entriesPerPages: number; resource: typeof Basket; type: string; _basket$: BehaviorSubject; _basketPreview$: BehaviorSubject; basketStats$: BehaviorSubject; currentAndPreviewFetching: BehaviorSubject; basketIsFetching$: BehaviorSubject; basketPreviewIsCalculating$: BehaviorSubject; basketInitCalled: boolean; recipesAdded: EventEmitter; recipesAddFailed: EventEmitter; confirming: BehaviorSubject; currentlyAddingRecipes: string[]; private basketActionsQueue; private currentSubscription; authlessTransferInProgress$: BehaviorSubject; private _entries$; private actionsBeingProcessed; private actionsBeingOverridden; private subscriptions; constructor(http: HttpClient, basketEntriesService: BasketEntriesService, posService: PointOfSalesService, recipesService: RecipesService, analyticsService: AnalyticsService, usersService: UserService, toasterService: ToasterService, ignoredBasketsService: IgnoredIngredientsService, statesService: StatesService, priceService: PriceService, menusService: MenusService); /** ************************************************************ GETTERS ************************************************************ **/ /** * We want basket$ to be a singleton that always returns the same basket, so it is fetched only when necessary. * At any point in time the basket can be fetched via the initBasket function (if we want to fetch it on startup to save time later) * But if initBasket is not called, the basket will only be fetched the 1st time it is needed. */ get basket$(): BehaviorSubject; /** * basketPreview$ should also be a singleton, and as well as basket$ it will be calculated for the first time only when necessary * or if loadPreview is called before */ get basketPreview$(): BehaviorSubject; /** * To use when needing to be sure that basket was fetched before doing an action that doesn't need to stay subscribed to basket$ * This method is meant to be an equivalent of basket$.value but asynchronous */ get waitForBasket(): Observable; /** * To use when needing to be sure that basket was fetched before doing an action that doesn't need to stay subscribed to basket$ * This method is meant to be an equivalent of basket$.value but asynchronous */ get waitForBasketEntries(): Observable; recipePricesInBasket$(): Observable<{ id: string; price: string; }[]>; /** ************************************************************ INIT ************************************************************ **/ private initQueueEmptying; private initToasterOnRecipeAdded; /** ************************************** QUEUE UTILS TO LOCK MORE ACTIONS OR DISPLAY LOADERS ************************************** **/ private subjectContainsRecipeId; private subjectContainsIngredientId; private subjectContainsEntryId; private subjectContainsItemId; private subjectContainsActionType; recipeWillBeAdded(recipeId: string): Observable; recipeWillBeRemoved(recipeId: string): Observable; recipeWillBeUpdated(recipeId: string): Observable; recipeIsBeingAdded(recipeId: string): Observable; recipeIsBeingRemoved(recipeId: string): Observable; recipeIsBeingUpdated(recipeId: string): Observable; ingredientWillBeAdded(ingredientId: string): Observable; ingredientIsBeingRemoved(ingredientId: string): Observable; ingredientWillBeRemoved(ingredientId: string): Observable; entryWillBeRemoved(entryId: string): Observable; entriesWillBeRemovedFromRecipe(): Observable; entryIsBeingRemoved(entryId: string): Observable; entriesAreBeingRemovedFromRecipe(): Observable; entryWillBeUpdated(entryId: string): Observable; entryIsBeingUpdated(entryId: string): Observable; itemWillBeAdded(itemId: string): Observable; recipesWillBeAdded(): Observable; recipesWillBeRemoved(): Observable; recipesWillBeUpdated(): Observable; productsWillBeAdded(): Observable; productsWillBeUpdated(): Observable; productsWillBeRemoved(): Observable; productsAreBeingRemoved(): Observable; /** ************************************************************* UTILS ************************************************************* **/ recipeIsInBasket(recipeId: string): Observable; guestsForRecipe(recipeId: string): number; private resolveGuestsForRecipe; /** * Waits until the given recipe is in the basket before resolving. * Emits `true` when the recipe is confirmed in the basket, `false` when its addition failed, * so callers can avoid firing dependent requests (e.g. add-ingredient) against a recipe that was never created. */ private waitUntilRecipeInBasket; private showRecipeAddedToaster; /** ***************************************************** LOAD / RELOAD / RESET ***************************************************** **/ reloadBasket(): Observable; initBasket(): void; refreshCurrentBasket(): Observable; private checkIfIsAffiliated; private transferAuthlessBasket; private fetchCurrentBasket; resetBasket(eventTrace?: EventTrace): Observable; /** ********************************************************* CONFIRM BASKET ********************************************************* **/ /** * Sends payment.confirm event then confirm basket if retailer's cart price and Mealz basket price are both non-zero * @param totalPrice The price of retailer's basket * @returns the current basket */ confirmPaymentAndBasket(totalPrice: number | string): Observable; /** * Tries to confirm basket. Sends analytic event and refresh current basket on successfull confirmation */ private confirmBasket; /** ******************************************************* ACTIONS ON ENTRIES ******************************************************* **/ basketEntries(): Observable; activeBasketEntries(): Observable; removeBasketEntries(entriesToRemove: ComparableProduct[]): Observable; removeBasketEntry(entryToRemove: ComparableProduct): Observable; /** * Fetches the BasketEntry for an ingredient if it exists * Returns a fake BasketEntry with id = -1 if it doesn't exist */ basketEntryFromIngredient(ingredientId: string, guests: number, onlyQuantity?: boolean, selectedItemId?: string): Observable; /** ******************************************************** ADD FROM PICTURE ******************************************************** **/ /** * Add entries to basket from a picture or file * @param file an image or PDF of a groceries list * @param include * @param isSchoolList if true, indicates to the api that the file is a school shopping list */ addEntriesFromPicture(file: File, include?: any[], isSchoolList?: boolean): Observable; /** **************************************************** ADD ACTIONS TO THE QUEUE **************************************************** **/ /** * Adds recipes to the basket action to queue. * * @param recipeIds - The array of recipe IDs to add. * @param guests - The number of guests. * @param eventTrace - The event trace. * @param withIngredients - Whether to include ingredients. Default is true. * @return This function does not return anything. */ addRecipesToBasket(recipeIds: string[], guests: number, eventTrace: EventTrace, withIngredients?: boolean): void; removeRecipesFromBasket(recipeIds: string[], eventTrace: EventTrace, lightMode?: boolean): void; updateRecipesInBasket(recipeIds: string[], guests: number, eventTrace: EventTrace, lightMode?: boolean): void; /** * This method is used both in the cas of adding an ingredient to basket and in the case of replacing the item of an ingredient * Because the same request is called at the end * @param recipeId Id of the recipe in which the ingredient is * @param ingredientIdsAndEntries pairs of ingredientId + basketEntry to add to basket * @param eventTrace eventTrace * @param previousItem (optional) previousItem in case of an item replacement (for analytics purposes) * @param searchString (optional) search_term in case of an item replacement when a search has been used (for analytics purposes) */ addIngredientsToBasket(recipeId: string, ingredientIdsAndEntries: { ingredientId: string; entry: BasketEntry; }[], eventTrace: EventTrace, previousItem?: Item, searchString?: string): void; addItemToBasket(item: Item, eventTrace: EventTrace, previousItem?: Item, forcedQuantity?: number): void; removeProductFromRecipe(products: { ingredient: Ingredient; basketEntry: BasketEntry; }[], eventTrace: EventTrace): void; removeIngredientsFromBasket(basketEntry: BasketEntry, recipeId: string, ingredientIds: string[], eventTrace: EventTrace): void; removeProduct(basketEntry: BasketEntry, eventTrace: EventTrace, recipeId?: string): void; changeProductQuantity(basketEntry: BasketEntry, newQuantity: number, eventTrace: EventTrace, recipeId?: string): void; /** *************************************************** PROCESS THE ACTIONS QUEUE *************************************************** **/ private emptyActionsQueue; /** * If multiple actions of the same type are next to each other in the queue, we want to process them as a batch. * @returns the next batch of actions to process */ private nextActionsBatch; /** * @returns true if the batch should stop processing */ private addActionToBatchOrStopProcessingBatch; private shouldForceStopBatch; /** * Check for actions for which overriding would have the same result as processing both in order */ private checkForActionToOverride; private processActionsBatch; /** ****************************************************** PROCESS THE ACTIONS ****************************************************** **/ /** * Adds recipes to the basket HTTP request. * * @param recipesToAdd - The recipes to add to the basket. * @param withIngredients - (optional) Whether to include ingredients in the request. Default is true. * @return An observable that emits void when the request is completed. */ private addRecipes; private addRecipesWithoutIngredients; private removeRecipes; removeRecipeById(recipeIdToRemove: string, analyticsPath: string, lightMode?: boolean): Observable; private updateRecipesGuests; /** * @param ingredientsToAdd */ private addItemsForIngredients; /** * Add items to the basket HTTP request. * * @param itemsToAdd - items to add to the basket * @return An observable that emits when the items are successfully added. */ private addItemsToBasket; /** * Removes the specified ingredients from the basket HTTP request. * * @param ingredientsToRemove - The list of ingredients to remove from the basket. * @return An observable that emits when the ingredients are successfully removed. */ private removeItemsForIngredients; private removeProductWithForcedQuantity; removeIngredientFromRecipe(basketEntry: BasketEntry, ingredientId: string, forcedQuantity: number): Observable; private removeIngredient; /** * Changes the quantities of basket entries. * * @param {BasketAction[]} quantitiesToChange - An array of BasketAction objects representing the quantities to change. * @return {Observable} An Observable that emits void when the quantities have been changed. */ private changeBasketEntriesQuantities; /** ****************************************************** UPDATING THE BASKET ****************************************************** **/ /** * Update _basket$ content & save basketId in the localStorage if the user is not loggued in so we can mergeWith when they log in */ private updateLocalBasket; /** * save() returns an object that isn't a resource so methods aren't attached, so we have to do a little trick * @param res result of the save * @returns correct Basket with the right attributes & methods */ private fillBasket; /** ********************************************************** INITIAL LOAD ********************************************************** **/ /** * Initialise the basket loading when the pos is initialised or modified * @returns _basket$ */ private loadBasket; private loadPreview; private fetchBasketEntries; private buildStats; private fetchBasketEntriesPage; private recipesAndLineEntriesToBasketPreviewLine; private groupBasketEntries; static ɵfac: i0.ɵɵFactoryDef; static ɵprov: i0.ɵɵInjectableDef; } //# sourceMappingURL=baskets.service.d.ts.map