From 72a889241e5d71831243131f3a759bcb10af6398 Mon Sep 17 00:00:00 2001 From: Bartosz Sekula Date: Wed, 5 Feb 2025 17:27:34 +0100 Subject: [PATCH] AAE-30901 Allow to use different saveSearch service (#10623) --- .../common/services/saved-searches.service.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/content-services/src/lib/common/services/saved-searches.service.ts b/lib/content-services/src/lib/common/services/saved-searches.service.ts index 3b538a6d9a..54bd86a848 100644 --- a/lib/content-services/src/lib/common/services/saved-searches.service.ts +++ b/lib/content-services/src/lib/common/services/saved-searches.service.ts @@ -15,28 +15,41 @@ * limitations under the License. */ -import { NodesApi, NodeEntry, PreferencesApi } from '@alfresco/js-api'; -import { Injectable } from '@angular/core'; +import { NodesApi, NodeEntry, PreferencesApi, ContentFieldsQuery, PreferenceEntry } from '@alfresco/js-api'; +import { inject, Injectable, InjectionToken } from '@angular/core'; import { Observable, of, from, ReplaySubject, throwError } from 'rxjs'; import { catchError, concatMap, first, map, switchMap, take, tap } from 'rxjs/operators'; import { AlfrescoApiService } from '../../services/alfresco-api.service'; import { SavedSearch } from '../interfaces/saved-search.interface'; import { AuthenticationService } from '@alfresco/adf-core'; +export interface SavedSearchesPreferencesApiService { + getPreference: (personId: string, preferenceName: string, opts?: ContentFieldsQuery) => Promise | Observable; + updatePreference: (personId: string, preferenceName: string, preferenceValue: string) => Promise | Observable; +} + +export const SAVED_SEARCHES_SERVICE_PREFERENCES = new InjectionToken('SAVED_SEARCHES_SERVICE_PREFERENCES'); + @Injectable({ providedIn: 'root' }) export class SavedSearchesService { private savedSearchFileNodeId: string; private _nodesApi: NodesApi; - private _preferencesApi: PreferencesApi; + private _preferencesApi: SavedSearchesPreferencesApiService; + private preferencesService = inject(SAVED_SEARCHES_SERVICE_PREFERENCES, { optional: true }); get nodesApi(): NodesApi { this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance()); return this._nodesApi; } - get preferencesApi(): PreferencesApi { + get preferencesApi(): SavedSearchesPreferencesApiService { + if (this.preferencesService) { + this._preferencesApi = this.preferencesService; + return this._preferencesApi; + } + this._preferencesApi = this._preferencesApi ?? new PreferencesApi(this.apiService.getInstance()); return this._preferencesApi; }