RED-7691: refactor code.
This commit is contained in:
parent
f09172490a
commit
4138f1b1e3
@ -18,7 +18,7 @@ import type {
|
||||
import { dictionaryActionsTranslations, manualRedactionActionsTranslations } from '@translations/annotation-actions-translations';
|
||||
import { Roles } from '@users/roles';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
import { EMPTY, of, OperatorFunction } from 'rxjs';
|
||||
import { EMPTY, of, OperatorFunction, pipe } from 'rxjs';
|
||||
import { catchError, tap } from 'rxjs/operators';
|
||||
|
||||
function getResponseType(error: boolean, isConflict: boolean) {
|
||||
@ -63,13 +63,11 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
|
||||
}
|
||||
|
||||
changeLegalBasis(body: List<ILegalBasisChangeRequest>, dossierId: string, fileId: string) {
|
||||
return this.legalBasisChange(body, dossierId, fileId).pipe(
|
||||
...(this.#showToast('change-legal-basis') as [OperatorFunction<unknown, unknown>]),
|
||||
);
|
||||
return this.legalBasisChange(body, dossierId, fileId).pipe(this.#showToast('change-legal-basis'));
|
||||
}
|
||||
|
||||
recategorizeRedactions(body: List<IRecategorizationRequest>, dossierId: string, fileId: string) {
|
||||
return this.recategorize(body, dossierId, fileId).pipe(...(this.#showToast('change-type') as [OperatorFunction<unknown, unknown>]));
|
||||
return this.recategorize(body, dossierId, fileId).pipe(this.#showToast('change-type'));
|
||||
}
|
||||
|
||||
addAnnotation(
|
||||
@ -79,32 +77,26 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
|
||||
options?: { hint?: boolean; dictionaryLabel?: string },
|
||||
) {
|
||||
const toast = requests[0].addToDictionary
|
||||
? [this.#showAddToDictionaryToast(requests, options?.dictionaryLabel)]
|
||||
? this.#showAddToDictionaryToast(requests, options?.dictionaryLabel)
|
||||
: this.#showToast(options?.hint ? 'force-hint' : 'add');
|
||||
const canAddRedaction = this._iqserPermissionsService.has(Roles.redactions.write);
|
||||
if (canAddRedaction) {
|
||||
return this.add(requests, dossierId, fileId).pipe(...(toast as [OperatorFunction<unknown, unknown>]));
|
||||
return this.add(requests, dossierId, fileId).pipe(toast);
|
||||
}
|
||||
|
||||
return of(undefined);
|
||||
}
|
||||
|
||||
bulkForce(requests: List<ILegalBasisChangeRequest>, dossierId: string, fileId: string, isIgnoredHint = false) {
|
||||
return this.forceRedaction(requests, dossierId, fileId).pipe(
|
||||
...(this.#showToast(!isIgnoredHint ? 'force-redaction' : 'force-hint') as [OperatorFunction<unknown, unknown>]),
|
||||
);
|
||||
return this.forceRedaction(requests, dossierId, fileId).pipe(this.#showToast(!isIgnoredHint ? 'force-redaction' : 'force-hint'));
|
||||
}
|
||||
|
||||
undoRequest(annotationIds: List, dossierId: string, fileId: string, modifyDictionary = false) {
|
||||
return this.undo(annotationIds, dossierId, fileId).pipe(
|
||||
...(this.#showToast('undo', modifyDictionary) as [OperatorFunction<unknown, unknown>]),
|
||||
);
|
||||
return this.undo(annotationIds, dossierId, fileId).pipe(this.#showToast('undo', modifyDictionary));
|
||||
}
|
||||
|
||||
removeRedaction(body: List<IRemoveRedactionRequest>, dossierId: string, fileId: string, removeFromDictionary = false, isHint = false) {
|
||||
return this.remove(body, dossierId, fileId).pipe(
|
||||
...(this.#showToast(!isHint ? 'remove' : 'remove-hint', removeFromDictionary) as [OperatorFunction<unknown, unknown>]),
|
||||
);
|
||||
return this.remove(body, dossierId, fileId).pipe(this.#showToast(!isHint ? 'remove' : 'remove-hint', removeFromDictionary));
|
||||
}
|
||||
|
||||
getTitle(type: ManualRedactionEntryType) {
|
||||
@ -157,8 +149,8 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
|
||||
});
|
||||
}
|
||||
|
||||
#showToast(action: ManualRedactionActions | DictionaryActions, isDictionary = false): OperatorFunction<unknown, unknown>[] {
|
||||
return [
|
||||
#showToast(action: ManualRedactionActions | DictionaryActions, isDictionary = false) {
|
||||
return pipe(
|
||||
catchError((error: unknown) => {
|
||||
const isConflict = (error as HttpErrorResponse).status === HttpStatusCode.Conflict;
|
||||
this._toaster.error(getMessage(action, isDictionary, true, isConflict), {
|
||||
@ -168,13 +160,12 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
|
||||
return EMPTY;
|
||||
}),
|
||||
tap(() => this._toaster.success(getMessage(action, isDictionary), { positionClass: 'toast-file-preview' })),
|
||||
];
|
||||
);
|
||||
}
|
||||
|
||||
#showAddToDictionaryToast(body: List<IAddRedactionRequest>, dictionaryLabel?: string) {
|
||||
return tap({
|
||||
next: () => this._toaster.success(getDictionaryMessage('add'), { positionClass: 'toast-file-preview' }),
|
||||
error: (error: unknown) => {
|
||||
return pipe(
|
||||
catchError((error: unknown) => {
|
||||
const isConflict = (error as HttpErrorResponse).status === HttpStatusCode.Conflict;
|
||||
this._toaster.error(getDictionaryMessage('add', true, isConflict), {
|
||||
error: error as HttpErrorResponse,
|
||||
@ -184,7 +175,11 @@ export class ManualRedactionService extends GenericService<IManualAddResponse> {
|
||||
},
|
||||
positionClass: 'toast-file-preview',
|
||||
});
|
||||
},
|
||||
});
|
||||
return EMPTY;
|
||||
}),
|
||||
tap({
|
||||
next: () => this._toaster.success(getDictionaryMessage('add'), { positionClass: 'toast-file-preview' }),
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user