{ "version": 3, "sources": ["apps/partner-center-client/src/app/user-permissions/associations.api.service.ts"], "sourcesContent": ["import { HttpHeaders } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { ApiService } from '../api-service/api.service';\nimport { ProductService } from '../core/product.service';\nimport { BrandAssociation } from './brand';\n\nexport interface AddBrandAssociationResponse {\n associationKey: string;\n label: string;\n productKey: string;\n productUserId: string;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class AssociationsApiService {\n constructor(private apiService: ApiService, private productService: ProductService) {}\n\n public deleteAccountGroupAssociation(userId: string, accountGroupId: string): Observable {\n const associationId = `${userId}-${accountGroupId}-AGID`;\n const url = `/bc-admin/user/${userId}/permissions/delete/`;\n return this.apiService.post(url, 'association_key=' + associationId, {\n headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }),\n });\n }\n\n public enableAllAccountAccess(accountGroupId: string, userId: string): Observable {\n const url = '/_ajax/v1/manage-users/permission/enable-all/';\n const data = {\n accountGroupId: accountGroupId,\n userId: userId,\n };\n return this.apiService.post(url, data);\n }\n\n public disableAllAccountAccess(accountGroupId: string, userId: string): Observable {\n const url = '/_ajax/v1/manage-users/permission/disable-all/';\n const data = {\n accountGroupId: accountGroupId,\n userId: userId,\n };\n return this.apiService.post(url, data);\n }\n\n public setAccountAccess(accountGroupId: string, userId: string, accountIds: string[]): Observable {\n const url = '/_ajax/v1/manage-users/permission/set/';\n const data = {\n accountGroupId: accountGroupId,\n userId: userId,\n accountIds: accountIds,\n };\n return this.apiService.post(url, data);\n }\n\n public addAssociations(userId: string, accountGroupIds: string[]): Observable {\n const url = '/_ajax/v1/associate-user-with-account-groups/';\n const data = {\n userId: userId,\n accountGroupIds: accountGroupIds,\n };\n return this.apiService.post(url, data);\n }\n\n public getAssociatedBrands(userId: string, partnerId: string): Observable {\n const url = '/_ajax/v1/user-association-lookup/';\n const data = {\n userId: userId,\n partnerId: partnerId,\n productId: 'NB',\n };\n const urlWithParams = this.apiService.generateUrlWithParams(url, data);\n return this.apiService.get(urlWithParams).pipe(\n map((resp) => {\n let brands = [];\n for (let i = 0; i < resp.length; i++) {\n if (resp[i].productId === 'NB') {\n brands = resp[i].associations;\n break;\n }\n }\n return brands.map((b) => {\n return {\n name: b.label,\n associationId: b.associationId,\n path: b.accountId,\n };\n });\n }),\n );\n }\n\n public deleteBrandAssociation(userId: string, associationId: string): Observable {\n const url = `/bc-admin/user/${userId}/permissions/delete/`;\n return this.apiService.post(url, 'association_key=' + encodeURIComponent(associationId), {\n headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }),\n });\n }\n\n public addBrandAssocation(userId: string, path: string): Observable {\n const encodedPath = encodeURIComponent(path);\n const url = `/bc-admin/user/${userId}/permissions/associate/`;\n return this.apiService\n .post(url, 'product_uid=' + encodedPath, {\n headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }),\n })\n .pipe(\n map((resp) => {\n return {\n associationKey: resp.association_key,\n label: resp.label,\n productKey: resp.product_key,\n productUserId: resp.productUserId,\n };\n }),\n );\n }\n}\n"], "mappings": "gLAgBA,IAAaA,GAAsB,IAAA,CAA7B,IAAOA,EAAP,MAAOA,CAAsB,CACjCC,YAAoBC,EAAgCC,EAA8B,CAA9D,KAAAD,WAAAA,EAAgC,KAAAC,eAAAA,CAAiC,CAE9EC,8BAA8BC,EAAgBC,EAAsB,CACzE,IAAMC,EAAgB,GAAGF,CAAM,IAAIC,CAAc,QAC3CE,EAAM,kBAAkBH,CAAM,uBACpC,OAAO,KAAKH,WAAWO,KAAKD,EAAK,mBAAqBD,EAAe,CACnEG,QAAS,IAAIC,EAAY,CAAE,eAAgB,mCAAmC,CAAE,EACjF,CACH,CAEOC,uBAAuBN,EAAwBD,EAAc,CAClE,IAAMG,EAAM,gDACNK,EAAO,CACXP,eAAgBA,EAChBD,OAAQA,GAEV,OAAO,KAAKH,WAAWO,KAAKD,EAAKK,CAAI,C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,CACpD,IAAMK,EAAcF,mBAAmBH,CAAI,EACrC3B,EAAM,kBAAkBH,CAAM,0BACpC,OAAO,KAAKH,WACTO,KAAKD,EAAK,eAAiBgC,EAAa,CACvC9B,QAAS,IAAIC,EAAY,CAAE,eAAgB,mCAAmC,CAAE,EACjF,EACAc,KACCC,EAAKC,IACI,CACLc,eAAgBd,EAAKe,gBACrBR,MAAOP,EAAKO,MACZS,WAAYhB,EAAKiB,YACjBC,cAAelB,EAAKkB,eAEvB,CAAC,CAER,yCApGW7C,GAAsB8C,EAAAC,CAAA,EAAAD,EAAAE,CAAA,CAAA,CAAA,wBAAtBhD,EAAsBiD,QAAtBjD,EAAsBkD,UAAAC,WADT,MAAM,CAAA,EAC1B,IAAOnD,EAAPoD,SAAOpD,CAAsB,GAAA", "names": ["AssociationsApiService", "constructor", "apiService", "productService", "deleteAccountGroupAssociation", "userId", "accountGroupId", "associationId", "url", "post", "headers", "HttpHeaders", "enableAllAccountAccess", "data", "disableAllAccountAccess", "setAccountAccess", "accountIds", "addAssociations", "accountGroupIds", "getAssociatedBrands", "partnerId", "productId", "urlWithParams", "generateUrlWithParams", "get", "pipe", "map", "resp", "brands", "i", "length", "associations", "b", "name", "label", "path", "accountId", "deleteBrandAssociation", "encodeURIComponent", "addBrandAssocation", "encodedPath", "associationKey", "association_key", "productKey", "product_key", "productUserId", "\u0275\u0275inject", "ApiService", "ProductService", "factory", "\u0275fac", "providedIn", "_AssociationsApiService"] }