|
|
|
@ -22,11 +22,11 @@ import { MatDialog } from '@angular/material/dialog'; |
|
|
|
import { |
|
|
|
EntityConflictDialogComponent |
|
|
|
} from '@shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component'; |
|
|
|
import { HasId } from '@shared/models/base-data'; |
|
|
|
import { HasVersion } from '@shared/models/entity.models'; |
|
|
|
import { EntityInfoData, VersionedEntity } from '@shared/models/entity.models'; |
|
|
|
import { getInterceptorConfig } from './interceptor.util'; |
|
|
|
import { isDefined } from '@core/utils'; |
|
|
|
import { InterceptorConfig } from '@core/interceptors/interceptor-config'; |
|
|
|
import { RuleChainMetaData } from '@shared/models/rule-chain.models'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
export class EntityConflictInterceptor implements HttpInterceptor { |
|
|
|
@ -35,7 +35,7 @@ export class EntityConflictInterceptor implements HttpInterceptor { |
|
|
|
private dialog: MatDialog, |
|
|
|
) {} |
|
|
|
|
|
|
|
intercept(request: HttpRequest<unknown & HasId & HasVersion>, next: HttpHandler): Observable<HttpEvent<unknown>> { |
|
|
|
intercept(request: HttpRequest<VersionedEntity>, next: HttpHandler): Observable<HttpEvent<unknown>> { |
|
|
|
if (!request.url.startsWith('/api/')) { |
|
|
|
return next.handle(request); |
|
|
|
} |
|
|
|
@ -52,11 +52,11 @@ export class EntityConflictInterceptor implements HttpInterceptor { |
|
|
|
} |
|
|
|
|
|
|
|
private handleConflictError( |
|
|
|
request: HttpRequest<unknown & HasId & HasVersion>, |
|
|
|
request: HttpRequest<VersionedEntity>, |
|
|
|
next: HttpHandler, |
|
|
|
error: HttpErrorResponse |
|
|
|
): Observable<HttpEvent<unknown>> { |
|
|
|
if (getInterceptorConfig(request).ignoreVersionConflict) { |
|
|
|
if (getInterceptorConfig(request).ignoreVersionConflict || !this.isVersionedEntity(request.body)) { |
|
|
|
return throwError(() => error); |
|
|
|
} |
|
|
|
|
|
|
|
@ -74,12 +74,16 @@ export class EntityConflictInterceptor implements HttpInterceptor { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private updateRequestVersion(request: HttpRequest<unknown & HasId & HasVersion>): HttpRequest<unknown & HasId & HasVersion> { |
|
|
|
private updateRequestVersion(request: HttpRequest<VersionedEntity>): HttpRequest<VersionedEntity> { |
|
|
|
const body = { ...request.body, version: null }; |
|
|
|
return request.clone({ body }); |
|
|
|
} |
|
|
|
|
|
|
|
private openConflictDialog(entity: unknown & HasId & HasVersion, message: string): Observable<boolean> { |
|
|
|
private isVersionedEntity(entity: VersionedEntity): boolean { |
|
|
|
return !!((entity as EntityInfoData)?.id ?? (entity as RuleChainMetaData)?.ruleChainId) |
|
|
|
} |
|
|
|
|
|
|
|
private openConflictDialog(entity: VersionedEntity, message: string): Observable<boolean> { |
|
|
|
const dialogRef = this.dialog.open(EntityConflictDialogComponent, { |
|
|
|
disableClose: true, |
|
|
|
data: { message, entity }, |
|
|
|
|