diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts index 8eb84a9e4747faea6e98f7d61fd27e76e9c10c23..1a8f122192eac7732110e0ee37b54244ed3234ab 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts +++ b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts @@ -7,7 +7,7 @@ import { } from '@alfa-client/tech-shared'; import { Injectable } from '@angular/core'; import { FormControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; -import { map, Observable, switchMap } from 'rxjs'; +import { map, Observable } from 'rxjs'; import { PostfachService } from '../../postfach.service'; import { Postfach, PostfachResource } from '../../postfach.model'; import { isNil } from 'lodash-es'; @@ -48,7 +48,7 @@ export class PostfachFormService extends AbstractFormService { if (this.shouldSkipAbsender(value)) { delete value.absender; } - return this.postfachService.save(value).pipe(switchMap(() => this.postfachService.get())); + return this.postfachService.save(value); } private shouldSkipAbsender(postfach: Postfach): boolean { diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.ts b/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.ts index 4fa62e36803d3ce3326f0d9b88e5dfe55b15c188..b35600877d2dffe3f97f487ac94b5a295ab04fc0 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.ts +++ b/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.ts @@ -4,7 +4,7 @@ import { Postfach, PostfachResource, PostfachSettingsItem } from './postfach.mod import { ResourceService } from 'libs/tech-shared/src/lib/resource/resource.service'; import { SettingsService } from '../admin-settings.service'; import { ResourceServiceConfig } from 'libs/tech-shared/src/lib/resource/resource.model'; -import { Observable, of, tap } from 'rxjs'; +import { Observable } from 'rxjs'; import { HttpError, StateResource } from '@alfa-client/tech-shared'; import { SettingName } from '../admin-settings.model'; import { PostfachLinkRel } from './postfach.linkrel'; diff --git a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts index 3311716c86977541f2d114b2ef74d8b5db0cdd38..08d197454b4224dc712dcaf47f1ed3f881fe6c34 100644 --- a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts +++ b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts @@ -1,15 +1,16 @@ import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; -import { Observable, lastValueFrom, of, throwError } from 'rxjs'; +import { lastValueFrom, Observable, of, throwError } from 'rxjs'; import { ResourceService } from './resource.service'; import { ResourceRepository } from './resource.repository'; import { LinkRelationName, ResourceServiceConfig, SaveResourceData } from './resource.model'; -import { Resource, getUrl } from '@ngxp/rest'; +import { getUrl, Resource } from '@ngxp/rest'; import { createDummyResource } from 'libs/tech-shared/test/resource'; +import * as ResourceUtil from './resource.util'; import { - StateResource, createEmptyStateResource, createErrorStateResource, createStateResource, + StateResource, } from './resource.util'; import { fakeAsync, tick } from '@angular/core/testing'; import { singleCold, singleHot } from './marbles'; @@ -18,8 +19,6 @@ import { createProblemDetail } from 'libs/tech-shared/test/error'; import { HttpError, ProblemDetail } from '../tech.model'; import { cold } from 'jest-marbles'; -import * as ResourceUtil from './resource.util'; - describe('ResourceService', () => { let service: ResourceService<Resource, Resource>; let config: ResourceServiceConfig<Resource>; @@ -443,6 +442,16 @@ describe('ResourceService', () => { expect(service.handleError).toHaveBeenCalledWith(errorResponse); }); + + it('should update state resource subject', fakeAsync(() => { + service.stateResource.next(createStateResource(resourceWithEditLinkRel)); + repository.save.mockReturnValue(of(loadedResource)); + + service.save(dummyToSave).subscribe(); + tick(); + + expect(service.stateResource.value).toEqual(createStateResource(loadedResource)); + })); }); describe('handleError', () => { diff --git a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts index c14a661395d83c8b9ff53fd4286ff4a2f7d2211d..a5a705e9d9b0369c2169f00075925c5a67bc4459 100644 --- a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts +++ b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts @@ -1,11 +1,10 @@ import { BehaviorSubject, - Observable, catchError, combineLatest, filter, map, - mergeMap, + Observable, of, startWith, tap, @@ -13,21 +12,20 @@ import { } from 'rxjs'; import { ResourceServiceConfig } from './resource.model'; import { - StateResource, createEmptyStateResource, createErrorStateResource, createStateResource, isLoadingRequired, + StateResource, throwErrorOn, } from './resource.util'; -import { Resource, getUrl, hasLink } from '@ngxp/rest'; +import { getUrl, hasLink, Resource } from '@ngxp/rest'; import { ResourceRepository } from './resource.repository'; import { isEqual, isNull } from 'lodash-es'; import { isNotNull } from '../tech.util'; import { HttpErrorResponse } from '@angular/common/http'; import { isUnprocessableEntity } from '../http.util'; import { HttpError, ProblemDetail } from '../tech.model'; -import { isDevMode } from '@angular/core'; /** * B = Type of baseresource @@ -146,11 +144,10 @@ export class ResourceService<B extends Resource, T extends Resource> { public save(toSave: unknown): Observable<StateResource<T | HttpError>> { this.verifyEditLinkRel(); - return this.stateResource.asObservable().pipe( - mergeMap((selectedResource: StateResource<T>) => - this.doSave(selectedResource.resource, toSave), - ), - map((loadedResource: T) => createStateResource(loadedResource)), + const previousResource: T = this.stateResource.value.resource; + return this.doSave(previousResource, toSave).pipe( + tap((loadedResource: T) => this.stateResource.next(createStateResource(loadedResource))), + map(() => this.stateResource.value), catchError((errorResponse: HttpErrorResponse) => this.handleError(errorResponse)), ); }