{ "version": 3, "sources": ["apps/business-center-client/src/app/reputation/reputation.service.ts"], "sourcesContent": ["import { Injectable } from '@angular/core';\nimport { GetSourceDetailsRequest, Source, SourceApiService } from '@vendasta/reputation';\nimport { Observable, combineLatest, map, shareReplay, switchMap, firstValueFrom } from 'rxjs';\nimport { partnerId } from '../../globals';\nimport { LocationsService, isBrand } from '../locations';\nimport { Channel, ReviewRequestApiService } from '@vendasta/reputation';\n\n@Injectable({ providedIn: 'root' })\nexport class ReputationService {\n partnerSourceDetailsMap$: Observable>;\n public brandSources$: Observable;\n public brandSourcesFull$: Observable>;\n\n constructor(\n readonly sourceApiService: SourceApiService,\n private locationsService: LocationsService,\n private reviewRequestApiService: ReviewRequestApiService,\n ) {\n this.partnerSourceDetailsMap$ = this.locationsService.marketId$.pipe(\n switchMap((marketId) => {\n return sourceApiService.getSourceDetails(\n new GetSourceDetailsRequest({\n partnerId: partnerId,\n marketId: marketId,\n }),\n );\n }),\n map((res) => res.sources),\n map((sources) => {\n const sourceMap = new Map();\n sources.forEach((source) => {\n sourceMap.set(source.sourceId + '', source);\n });\n return sourceMap;\n }),\n shareReplay({ refCount: true, bufferSize: 1 }),\n );\n\n this.brandSources$ = combineLatest([this.locationsService.currentLocation$, this.partnerSourceDetailsMap$]).pipe(\n map(([brand, sourceDetailsMap]) => {\n if (!isBrand(brand)) {\n // TODO: There is a list of sources for an account that we can use instead of the partner's here,\n // but we may need to get it directly from reputation management...\n return Array.from(sourceDetailsMap.keys()).map((k) => parseInt(k, 10));\n }\n\n // This filter exists to filter out sources that are not available on the partner but that are enabled\n // on the brand. This can be sources that were disabled on the PID after the brand was created, sources\n // that are no longer available for whatever reason, or sources that were erroneously enabled on a\n // brand in some other way.\n return brand.activatedSources.filter((srcId) => sourceDetailsMap.has(srcId + ''));\n }),\n shareReplay({ refCount: true, bufferSize: 1 }),\n );\n\n this.brandSourcesFull$ = combineLatest([this.partnerSourceDetailsMap$, this.brandSources$]).pipe(\n map(([sourceDetailsMap, activatedSources]: [Map, number[]]) => {\n return activatedSources.reduce((srcs, srcId) => {\n const src = sourceDetailsMap.get(srcId + '');\n if (src) {\n srcs.set(srcId + '', src);\n }\n return srcs;\n }, new Map());\n }),\n );\n }\n\n async scheduleReviewRequest(accountGroupId: string, contactIds: string[]) {\n const req = {\n accountGroupId: accountGroupId,\n contactIds: contactIds,\n channel: Channel.SMS_FALLBACK_TO_EMAIL,\n sendNow: true,\n };\n await firstValueFrom(this.reviewRequestApiService.scheduleReviewRequest(req));\n }\n}\n"], "mappings": "8TAAA,IAQaA,EARbC,EAAAC,EAAA,KACAC,IACAC,IACAC,IACAC,IACAH,gBAGaH,GAAiB,IAAA,CAAxB,MAAOA,CAAiB,CAK5BO,YACWC,EACDC,EACAC,EAAgD,CAF/C,KAAAF,iBAAAA,EACD,KAAAC,iBAAAA,EACA,KAAAC,wBAAAA,EAER,KAAKC,yBAA2B,KAAKF,iBAAiBG,UAAUC,KAC9DC,EAAWC,GACFP,EAAiBQ,iBACtB,IAAIC,EAAwB,CAC1BC,UAAWA,EACXH,SAAUA,EACX,CAAC,CAEL,EACDI,EAAKC,GAAQA,EAAIC,OAAO,EACxBF,EAAKE,GAAW,CACd,IAAMC,EAAY,IAAIC,IACtBF,OAAAA,EAAQG,QAASC,GAAU,CACzBH,EAAUI,IAAID,EAAOE,SAAW,GAAIF,CAAM,CAC5C,CAAC,EACMH,CACT,CAAC,EACDM,EAAY,CAAEC,SAAU,GAAMC,WAAY,CAAC,CAAE,CAAC,EAGhD,KAAKC,cAAgBC,EAAc,CAAC,KAAKvB,iBAAiBwB,iBAAkB,KAAKtB,wBAAwB,CAAC,EAAEE,KAC1GM,EAAI,CAAC,CAACe,EAAOC,CAAgB,IACtBC,EAAQF,CAAK,EAUXA,EAAMG,iBAAiBC,OAAQC,GAAUJ,EAAiBK,IAAID,EAAQ,EAAE,CAAC,EAPvEE,MAAMC,KAAKP,EAAiBQ,KAAI,CAAE,EAAExB,IAAKyB,GAAMC,SAASD,EAAG,EAAE,CAAC,CAQxE,EACDhB,EAAY,CAAEC,SAAU,GAAMC,WAAY,CAAC,CAAE,CAAC,EAGhD,KAAKgB,kBAAoBd,EAAc,CAAC,KAAKrB,yBAA0B,KAAKoB,aAAa,CAAC,EAAElB,KAC1FM,EAAI,CAAC,CAACgB,EAAkBE,CAAgB,IAC/BA,EAAiBU,OAAO,CAACC,EAAMT,IAAS,CAC7C,IAAMU,EAAMd,EAAiBe,IAAIX,EAAQ,EAAE,EAC3C,OAAIU,GACFD,EAAKtB,IAAIa,EAAQ,GAAIU,CAAG,EAEnBD,CACT,EAAG,IAAIzB,GAAqB,CAC7B,CAAC,CAEN,CAEM4B,sBAAsBC,EAAwBC,EAAoB,QAAAC,EAAA,sBACtE,IAAMC,EAAM,CACVH,eAAgBA,EAChBC,WAAYA,EACZG,QAASC,EAAQC,sBACjBC,QAAS,IAEX,MAAMC,EAAe,KAAKlD,wBAAwByC,sBAAsBI,CAAG,CAAC,CAC9E,mDApEWvD,GAAiB6D,EAAAC,CAAA,EAAAD,EAAAE,CAAA,EAAAF,EAAAG,CAAA,CAAA,CAAA,CAAA,iCAAjBhE,EAAiBiE,QAAjBjE,EAAiBkE,UAAAC,WADJ,MAAM,CAAA,CAAA,SACnBnE,CAAiB,GAAA", "names": ["ReputationService", "init_reputation_service", "__esmMin", "init_vendasta_reputation", "init_esm", "init_globals", "init_locations", "constructor", "sourceApiService", "locationsService", "reviewRequestApiService", "partnerSourceDetailsMap$", "marketId$", "pipe", "switchMap", "marketId", "getSourceDetails", "GetSourceDetailsRequest", "partnerId", "map", "res", "sources", "sourceMap", "Map", "forEach", "source", "set", "sourceId", "shareReplay", "refCount", "bufferSize", "brandSources$", "combineLatest", "currentLocation$", "brand", "sourceDetailsMap", "isBrand", "activatedSources", "filter", "srcId", "has", "Array", "from", "keys", "k", "parseInt", "brandSourcesFull$", "reduce", "srcs", "src", "get", "scheduleReviewRequest", "accountGroupId", "contactIds", "__async", "req", "channel", "Channel", "SMS_FALLBACK_TO_EMAIL", "sendNow", "firstValueFrom", "\u0275\u0275inject", "SourceApiService", "LocationsService", "ReviewRequestApiService", "factory", "\u0275fac", "providedIn"] }