Skip to content

Commit 1ce0d56

Browse files
authored
Fix/ang-905 - Component creation (#580)
* fix(ang-905): fixed create component affiliations issue * fix(ang-905): fixed component creation institutions absence
1 parent 9e86345 commit 1ce0d56

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export class AddComponentDialogComponent implements OnInit {
157157
.filter((inst) => inst !== undefined);
158158

159159
this.selectedInstitutions.set(matchedInstitutions);
160+
161+
const institutionIds = matchedInstitutions.map((inst) => inst.id);
162+
this.componentForm.get(ComponentFormControls.Affiliations)?.setValue(institutionIds);
160163
}
161164
});
162165
}

src/app/features/project/overview/services/project-overview.service.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Observable } from 'rxjs';
2-
import { map } from 'rxjs/operators';
1+
import { Observable, of } from 'rxjs';
2+
import { map, switchMap } from 'rxjs/operators';
33

44
import { inject, Injectable } from '@angular/core';
55

@@ -122,11 +122,29 @@ export class ProjectOverviewService {
122122
params['region'] = region;
123123
}
124124

125-
if (affiliatedInstitutions.length) {
126-
params['affiliated_institutions'] = affiliatedInstitutions;
127-
}
128-
129-
return this.jsonApiService.post<void>(`${this.apiUrl}/nodes/${projectId}/children/`, payload, params);
125+
return this.jsonApiService
126+
.post<JsonApiResponse<BaseNodeDataJsonApi, null>>(`${this.apiUrl}/nodes/${projectId}/children/`, payload, params)
127+
.pipe(
128+
switchMap((response) => {
129+
const componentId = response.data.id;
130+
131+
if (affiliatedInstitutions.length) {
132+
const affiliationsPayload = {
133+
data: affiliatedInstitutions.map((id) => ({
134+
type: 'institutions',
135+
id,
136+
})),
137+
};
138+
139+
return this.jsonApiService.patch<void>(
140+
`${this.apiUrl}/nodes/${componentId}/relationships/institutions/`,
141+
affiliationsPayload
142+
);
143+
}
144+
145+
return of(undefined);
146+
})
147+
);
130148
}
131149

132150
deleteComponent(componentId: string): Observable<void> {

src/app/features/registry/registry.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export class RegistryComponent implements OnDestroy {
6666
});
6767

6868
this.dataciteService.logIdentifiableView(this.registry$).pipe(takeUntilDestroyed(this.destroyRef)).subscribe();
69-
7069
}
7170

7271
ngOnDestroy(): void {

0 commit comments

Comments
 (0)