diff --git a/apps/red-ui/src/app/services/entity-services/dictionary.service.ts b/apps/red-ui/src/app/services/entity-services/dictionary.service.ts index dee8cf209..aa91e81f0 100644 --- a/apps/red-ui/src/app/services/entity-services/dictionary.service.ts +++ b/apps/red-ui/src/app/services/entity-services/dictionary.service.ts @@ -1,7 +1,7 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { EntitiesService, getConfig, isIqserDevMode, QueryParam, Toaster } from '@iqser/common-ui'; +import { EntitiesService, isIqserDevMode, Toaster } from '@iqser/common-ui'; import { List } from '@iqser/common-ui/lib/utils'; import { Dictionary, DictionaryEntryType, DictionaryEntryTypes, IDictionary, IUpdateDictionary, SuperTypes } from '@red/domain'; import { firstValueFrom, forkJoin, Observable } from 'rxjs'; @@ -112,23 +112,18 @@ export class DictionaryService extends EntitiesService } entriesToAdd.push(entry); } - const deletedEntries: Array = []; + const entriesToDelete: Array = []; const entriesSet = new Set(entries); for (let i = 0; i < initialEntries.length; i++) { const entry = initialEntries.at(i); if (entriesSet.has(entry)) { continue; } - deletedEntries.push(entry); + entriesToDelete.push(entry); } try { - if (deletedEntries.length) { - await this.#deleteEntries(deletedEntries, dossierTemplateId, type, dictionaryEntryType, dossierId); - } - if (entriesToAdd.length) { - await this.#addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId); - } + await this.#updateEntries(entriesToAdd, entriesToDelete, dossierTemplateId, type, dictionaryEntryType, dossierId); if (showToast) { this._toaster.success(_('dictionary-overview.success.generic')); @@ -249,30 +244,20 @@ export class DictionaryService extends EntitiesService return forkJoin(requests); } - /** - * Add dictionary entries with entry type. - */ - - #addEntries(entries: List, dossierTemplateId: string, type: string, dictionaryEntryType: DictionaryEntryType, dossierId: string) { - const queryParams: List = [ - { key: 'dossierId', value: dossierId }, - { key: 'dictionaryEntryType', value: dictionaryEntryType }, - ]; - const url = `${this._defaultModelPath}/${type}/${dossierTemplateId}`; - return firstValueFrom(this._post(entries, url, queryParams)); - } - - /** - * Delete dictionary entries with entry type. - */ - - #deleteEntries(entries: List, dossierTemplateId: string, type: string, dictionaryEntryType: DictionaryEntryType, dossierId: string) { + #updateEntries( + entriesToAdd: List, + entriesToDelete: List, + dossierTemplateId: string, + type: string, + dictionaryEntryType: DictionaryEntryType, + dossierId: string, + ) { const queryParams = [ { key: 'dossierId', value: dossierId }, { key: 'dictionaryEntryType', value: dictionaryEntryType }, ]; - const url = `${this._defaultModelPath}/delete/${type}/${dossierTemplateId}`; - return firstValueFrom(this._post(entries, url, queryParams)); + const url = `${this._defaultModelPath}/update/${type}/${dossierTemplateId}`; + return firstValueFrom(this._post({ entriesToAdd, entriesToDelete }, url, queryParams)); } #extractDossierLevelTypes(dossierId: string) {