{ "version": 3, "sources": ["src/app/services/Wishlists/wishlist.service.ts"], "sourcesContent": ["import {computed, Injectable, signal} from '@angular/core';\r\nimport {toObservable} from \"@angular/core/rxjs-interop\";\r\nimport {CampagneProduct} from \"../../models/Campagne/CampagneProduct\";\r\nimport {Wishlist, WishlistLight, WishlistLigne} from \"../../models/Wishlist/Wishlist\";\r\nimport { HttpClient } from \"@angular/common/http\";\r\nimport {environment} from \"../../../environments/environment\";\r\nimport {firstValueFrom, lastValueFrom, Subject,} from \"rxjs\";\r\nimport {TypeCampagne} from \"../../models/Campagne/TypeCampagne\";\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class WishlistService {\r\n apiGccUrl = environment.api + 'bff/';\r\n\r\n type = signal(null);\r\n primeursWishlist = signal(undefined);\r\n primeursWlLignes = computed(() => this.primeursWishlist()?.wishlistLignes);\r\n primeursWlLignes$ = toObservable(this.primeursWlLignes);\r\n memWishlist = signal(undefined);\r\n memWlLignes = computed(() => this.memWishlist()?.wishlistLignes);\r\n memWlLignes$ = toObservable(this.memWlLignes);\r\n listIdVinPrimeursWish = signal([]);\r\n listIdVinPrimeursWish$ = toObservable(this.listIdVinPrimeursWish);\r\n listIdVinMemWish = signal([]);\r\n listIdVinMemWish$ = toObservable(this.listIdVinMemWish);\r\n visible = signal(false);\r\n visible$ = toObservable(this.visible);\r\n product = signal(null);\r\n product$ = toObservable(this.product);\r\n\r\n reloadTablePrimeur$ = new Subject();\r\n\r\n constructor(private http: HttpClient) { }\r\n\r\n async add(wishlistLigne: WishlistLigne, idWishlist: number | null) {\r\n\r\n const data = await firstValueFrom(this.addToWishlist(this.createWishlistLight(wishlistLigne, idWishlist)));\r\n\r\n if (wishlistLigne.pays) {\r\n data.pays = wishlistLigne.pays;\r\n }\r\n\r\n this.handleWishlistPrimeurOrMem(data);\r\n\r\n }\r\n\r\n addExistingWishlistLigne(wishlistLigne: WishlistLigne){\r\n this.handleWishlistPrimeurOrMem(wishlistLigne);\r\n }\r\n\r\n handleWishlistPrimeurOrMem(data: WishlistLigne){\r\n if (this.type() === TypeCampagne.Primeurs) {\r\n data.typeCampagne = TypeCampagne.Primeurs\r\n if (!this.primeursWishlist()) {\r\n const tempWl: Wishlist = {\r\n idWishlist: data.idWishlist,\r\n wishlistLignes: [],\r\n typeCampagne: TypeCampagne.Primeurs\r\n }\r\n this.primeursWishlist.set(tempWl);\r\n this.listIdVinPrimeursWish.set([]);\r\n }\r\n this.primeursWishlist()?.wishlistLignes?.push(data);\r\n this.listIdVinPrimeursWish().push(data.idVin!);\r\n this.listIdVinPrimeursWish.set(this.listIdVinPrimeursWish());\r\n\r\n } else if (this.type() === TypeCampagne.MiseEnMarche) {\r\n data.typeCampagne = TypeCampagne.MiseEnMarche\r\n if (!this.memWishlist()) {\r\n const tempWl: Wishlist = {\r\n idWishlist: data.idWishlist,\r\n wishlistLignes: [],\r\n typeCampagne: TypeCampagne.MiseEnMarche\r\n }\r\n this.memWishlist.set(tempWl);\r\n this.listIdVinMemWish.set([]);\r\n }\r\n this.memWishlist()?.wishlistLignes?.push(data);\r\n this.listIdVinMemWish().push(data.idVin!);\r\n this.listIdVinMemWish.set(this.listIdVinMemWish());\r\n }\r\n }\r\n\r\n createWishlistLight(wishlistLigne: WishlistLigne, idWishlist: number | null): WishlistLight {\r\n return {\r\n idWishlist: idWishlist ?? null,\r\n millesime: wishlistLigne.millesime,\r\n idVin: wishlistLigne.idVin,\r\n nomVin: wishlistLigne.nomVin,\r\n nomAppellation: wishlistLigne.nomAppellation,\r\n couleur: wishlistLigne.couleur,\r\n quantite: wishlistLigne.quantite,\r\n typeCampagne: wishlistLigne.typeCampagne,\r\n pays: wishlistLigne.pays\r\n }\r\n }\r\n\r\n remove(idVin: string, type: TypeCampagne, millesime?: string) {\r\n let wishlist: Wishlist | null |undefined, listIdVinWish: string[] = [];\r\n\r\n if (type === TypeCampagne.Primeurs) {\r\n wishlist = this.primeursWishlist();\r\n listIdVinWish = this.listIdVinPrimeursWish();\r\n } else if (type === TypeCampagne.MiseEnMarche) {\r\n wishlist = this.memWishlist();\r\n listIdVinWish = this.listIdVinMemWish();\r\n }\r\n\r\n if (!wishlist || !listIdVinWish.length) {\r\n return;\r\n }\r\n const idWishlistLigne = wishlist.wishlistLignes?.find(wl => (wl.idVin === idVin && wl.millesime === millesime))?.idWishlistLigne;\r\n if (idWishlistLigne) {\r\n this.deleteFromWishlist(idWishlistLigne).then(() => {\r\n const index = wishlist?.wishlistLignes!.findIndex(p => p.idVin === idVin);\r\n if (index !== -1) {\r\n wishlist?.wishlistLignes?.splice(index!, 1);\r\n }\r\n\r\n const indexList = listIdVinWish.findIndex(id => id === idVin);\r\n if (indexList !== -1) {\r\n listIdVinWish.splice(indexList, 1);\r\n }\r\n });\r\n }\r\n }\r\n\r\n show(product: CampagneProduct | undefined, type: TypeCampagne) {\r\n this.type.set(type);\r\n if(product)\r\n this.product.set(product);\r\n this.visible.set(true);\r\n }\r\n\r\n hide() {\r\n this.type.set(null);\r\n this.product.set(null);\r\n this.visible.set(false);\r\n }\r\n\r\n //HTTP\r\n async getWislistPrimeurs(millesime: string) {\r\n if (typeof (this.primeursWishlist()) === 'undefined') {\r\n const data = await firstValueFrom(this.http.get(this.apiGccUrl + 'Wishlist/GetWishlistPrimeurs', {params: {millesime}}));\r\n this.primeursWishlist.set(data);\r\n this.listIdVinPrimeursWish.set(data?.wishlistLignes!.map(w => w.idVin!));\r\n }\r\n }\r\n\r\n async getWishlistMem() {\r\n if (typeof (this.memWishlist()) === 'undefined') {\r\n const data = await firstValueFrom(this.http.get(this.apiGccUrl + 'Wishlist/GetWishlistMem'));\r\n this.memWishlist.set(data);\r\n this.listIdVinMemWish.set(data?.wishlistLignes!.map(w => w.idVin!));\r\n }\r\n }\r\n\r\n addToWishlist(data: any) {\r\n return this.http.post(this.apiGccUrl + 'Wishlist/AddToWishlist', data);\r\n }\r\n\r\n updateWishlist(wishlist: Wishlist | undefined | null) {\r\n return this.http.post(this.apiGccUrl + 'WishList/UpdateWishlist', wishlist);\r\n }\r\n\r\n deleteFromWishlist(idWishlistLigne: number) {\r\n return lastValueFrom(this.http.delete(this.apiGccUrl + 'Wishlist/DeleteFromWishlist/' + idWishlistLigne));\r\n }\r\n\r\n createWishlistVinNonSorti(wishlistToCreate: {\r\n quantite: number;\r\n typeCampagne: TypeCampagne | null;\r\n idVin: string;\r\n millesime: string;\r\n idWishlist: number | null | undefined\r\n }) {\r\n return this.http.post(this.apiGccUrl + 'Wishlist/AddToWishlistVinNonSorti', wishlistToCreate)\r\n }\r\n}\r\n"], "mappings": "2LAYA,IAAaA,GAAe,IAAA,CAAtB,MAAOA,CAAe,CAqB1BC,YAAoBC,EAAgB,CAAhB,KAAAA,KAAAA,EApBpB,KAAAC,UAAYC,EAAYC,IAAM,OAE9B,KAAAC,KAAOC,EAA4B,IAAI,EACvC,KAAAC,iBAAmBD,EAAoCE,MAAS,EAChE,KAAAC,iBAAmBC,EAAS,IAAM,KAAKH,iBAAgB,GAAII,cAAc,EACzE,KAAAC,kBAAoBC,EAAa,KAAKJ,gBAAgB,EACtD,KAAAK,YAAcR,EAAoCE,MAAS,EAC3D,KAAAO,YAAcL,EAAS,IAAM,KAAKI,YAAW,GAAIH,cAAc,EAC/D,KAAAK,aAAeH,EAAa,KAAKE,WAAW,EAC5C,KAAAE,sBAAwBX,EAAiB,CAAA,CAAE,EAC3C,KAAAY,uBAAyBL,EAAa,KAAKI,qBAAqB,EAChE,KAAAE,iBAAmBb,EAAiB,CAAA,CAAE,EACtC,KAAAc,kBAAoBP,EAAa,KAAKM,gBAAgB,EACtD,KAAAE,QAAUf,EAAO,EAAK,EACtB,KAAAgB,SAAWT,EAAa,KAAKQ,OAAO,EACpC,KAAAE,QAAUjB,EAA+B,IAAI,EAC7C,KAAAkB,SAAWX,EAAa,KAAKU,OAAO,EAEpC,KAAAE,oBAAsB,IAAIC,CAEc,CAElCC,IAAIC,EAA8BC,EAAyB,QAAAC,EAAA,sBAE/D,IAAMC,EAAO,MAAMC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KvB,iBAAgB,EAAQ,IAAa,CACpD,IAAMwB,EAAO,MAAMC,EAAe,KAAK/B,KAAKoE,IAAc,KAAKnE,UAAY,+BAAgC,CAACoE,OAAQ,CAACxB,UAAAA,CAAS,CAAC,CAAC,CAAC,EACjI,KAAKvC,iBAAiBmC,IAAIX,CAAI,EAC9B,KAAKd,sBAAsByB,IAAIX,GAAMpB,eAAgB4D,IAAIC,GAAKA,EAAE5B,KAAM,CAAC,CACzE,CACF,GAEM6B,gBAAc,QAAA3C,EAAA,sBAClB,GAAI,OAAQ,KAAKhB,YAAW,EAAQ,IAAa,CAC/C,IAAMiB,EAAO,MAAMC,EAAe,KAAK/B,KAAKoE,IAAc,KAAKnE,UAAY,yBAAyB,CAAC,EACrG,KAAKY,YAAY4B,IAAIX,CAAI,EACzB,KAAKZ,iBAAiBuB,IAAIX,GAAMpB,eAAgB4D,IAAIC,GAAKA,EAAE5B,KAAM,CAAC,CACpE,CACF,GAEAX,cAAcF,EAAS,CACrB,OAAO,KAAK9B,KAAKyE,KAAoB,KAAKxE,UAAY,yBAA0B6B,CAAI,CACtF,CAEA4C,eAAevB,EAAqC,CAClD,OAAO,KAAKnD,KAAKyE,KAAe,KAAKxE,UAAY,0BAA2BkD,CAAQ,CACtF,CAEAM,mBAAmBH,EAAuB,CACxC,OAAOqB,EAAc,KAAK3E,KAAK4E,OAA6B,KAAK3E,UAAY,+BAAiCqD,CAAe,CAAC,CAChI,CAEAuB,0BAA0BC,EAMzB,CACC,OAAO,KAAK9E,KAAKyE,KAAoB,KAAKxE,UAAY,oCAAqC6E,CAAgB,CAC7G,iDAtKWhF,GAAeiF,EAAAC,CAAA,CAAA,CAAA,CAAA,iCAAflF,EAAemF,QAAfnF,EAAeoF,UAAAC,WAFd,MAAM,CAAA,CAAA,SAEPrF,CAAe,GAAA", "names": ["WishlistService", "constructor", "http", "apiGccUrl", "environment", "api", "type", "signal", "primeursWishlist", "undefined", "primeursWlLignes", "computed", "wishlistLignes", "primeursWlLignes$", "toObservable", "memWishlist", "memWlLignes", "memWlLignes$", "listIdVinPrimeursWish", "listIdVinPrimeursWish$", "listIdVinMemWish", "listIdVinMemWish$", "visible", "visible$", "product", "product$", "reloadTablePrimeur$", "Subject", "add", "wishlistLigne", "idWishlist", "__async", "data", "firstValueFrom", "addToWishlist", "createWishlistLight", "pays", "handleWishlistPrimeurOrMem", "addExistingWishlistLigne", "TypeCampagne", "Primeurs", "typeCampagne", "tempWl", "set", "push", "idVin", "MiseEnMarche", "millesime", "nomVin", "nomAppellation", "couleur", "quantite", "remove", "wishlist", "listIdVinWish", "length", "idWishlistLigne", "find", "wl", "deleteFromWishlist", "then", "index", "findIndex", "p", "splice", "indexList", "id", "show", "hide", "getWislistPrimeurs", "get", "params", "map", "w", "getWishlistMem", "post", "updateWishlist", "lastValueFrom", "delete", "createWishlistVinNonSorti", "wishlistToCreate", "\u0275\u0275inject", "HttpClient", "factory", "\u0275fac", "providedIn"] }