Avoid retrieving user suggestions if Researcher profiles are disabled

This commit is contained in:
Toni Prieto
2025-02-03 10:47:40 +01:00
parent e867993bb8
commit 72919cd867

View File

@@ -13,6 +13,10 @@ import {
switchMap, switchMap,
tap, tap,
} from 'rxjs/operators'; } from 'rxjs/operators';
import { ConfigurationDataService } from 'src/app/core/data/configuration-data.service';
import { RemoteData } from 'src/app/core/data/remote-data';
import { ConfigurationProperty } from 'src/app/core/shared/configuration-property.model';
import { getFirstCompletedRemoteData } from 'src/app/core/shared/operators';
import { import {
AuthActionTypes, AuthActionTypes,
@@ -72,14 +76,23 @@ export class SuggestionTargetsEffects {
), { dispatch: false }); ), { dispatch: false });
/** /**
* Show a notification on error. * Retrieve the current user suggestions after retrieving the authenticated user
*/ */
retrieveUserTargets$ = createEffect(() => this.actions$.pipe( retrieveUserTargets$ = createEffect(() => this.actions$.pipe(
ofType(AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS), ofType(AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS),
switchMap((action: RetrieveAuthenticatedEpersonSuccessAction) => { switchMap((action: RetrieveAuthenticatedEpersonSuccessAction) => {
return this.suggestionsService.retrieveCurrentUserSuggestions(action.payload).pipe( return this.configurationService.findByPropertyName('researcher-profile.entity-type').pipe(
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)), getFirstCompletedRemoteData(),
); switchMap((configRD: RemoteData<ConfigurationProperty> ) => {
if (configRD.hasSucceeded && configRD.payload.values.length > 0) {
return this.suggestionsService.retrieveCurrentUserSuggestions(action.payload).pipe(
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
);
} else {
return of(new AddUserSuggestionsAction([]));
}
},
));
}))); })));
/** /**
@@ -91,16 +104,35 @@ export class SuggestionTargetsEffects {
return this.store$.select((state: any) => state.core.auth.userId) return this.store$.select((state: any) => state.core.auth.userId)
.pipe( .pipe(
switchMap((userId: string) => { switchMap((userId: string) => {
return this.suggestionsService.retrieveCurrentUserSuggestions(userId) if (!userId) {
.pipe( return of(new AddUserSuggestionsAction([]));
map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)), }
catchError((error: unknown) => { return this.configurationService.findByPropertyName('researcher-profile.entity-type').pipe(
if (error instanceof Error) { getFirstCompletedRemoteData(),
console.error(error.message); switchMap((configRD: RemoteData<ConfigurationProperty> ) => {
} if (configRD.hasSucceeded && configRD.payload.values.length > 0) {
return of(new RefreshUserSuggestionsErrorAction()); return this.suggestionsService.retrieveCurrentUserSuggestions(userId)
}), .pipe(
); map((suggestionTargets: SuggestionTarget[]) => new AddUserSuggestionsAction(suggestionTargets)),
catchError((error: unknown) => {
if (error instanceof Error) {
console.error(error.message);
}
return of(new RefreshUserSuggestionsErrorAction());
}),
);
} else {
return of(new AddUserSuggestionsAction([]));
}
},
),
catchError((error: unknown) => {
if (error instanceof Error) {
console.error(error.message);
}
return of(new RefreshUserSuggestionsErrorAction());
}),
);
}), }),
catchError((error: unknown) => { catchError((error: unknown) => {
if (error instanceof Error) { if (error instanceof Error) {
@@ -119,6 +151,7 @@ export class SuggestionTargetsEffects {
* @param {TranslateService} translate * @param {TranslateService} translate
* @param {NotificationsService} notificationsService * @param {NotificationsService} notificationsService
* @param {SuggestionsService} suggestionsService * @param {SuggestionsService} suggestionsService
* @param {ConfigurationDataService} configurationService
*/ */
constructor( constructor(
private actions$: Actions, private actions$: Actions,
@@ -126,6 +159,7 @@ export class SuggestionTargetsEffects {
private translate: TranslateService, private translate: TranslateService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private suggestionsService: SuggestionsService, private suggestionsService: SuggestionsService,
private configurationService: ConfigurationDataService,
) { ) {
} }
} }