Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';

import { HttpContext } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';

import { BYPASS_ERROR_INTERCEPTOR } from '@core/interceptors/error-interceptor.tokens';
import { ENVIRONMENT } from '@core/provider/environment.provider';
import { BaseNodeMapper, ComponentsMapper } from '@osf/shared/mappers';
import {
Expand Down Expand Up @@ -167,11 +169,17 @@ export class ProjectOverviewService {
'embed[]': ['bibliographic_contributors'],
'fields[users]': 'family_name,full_name,given_name,middle_name',
};
return this.jsonApiService.get<ProjectOverviewResponseJsonApi>(`${this.apiUrl}/nodes/${projectId}/`, params).pipe(
map((response) => ({
project: ProjectOverviewMapper.fromGetProjectResponse(response.data),
meta: response.meta,
}))
);

const context = new HttpContext();
context.set(BYPASS_ERROR_INTERCEPTOR, true);

return this.jsonApiService
.get<ProjectOverviewResponseJsonApi>(`${this.apiUrl}/nodes/${projectId}/`, params, context)
.pipe(
map((response) => ({
project: ProjectOverviewMapper.fromGetProjectResponse(response.data),
meta: response.meta,
}))
);
}
}
12 changes: 2 additions & 10 deletions src/app/shared/services/addons/addons.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,15 @@ export class AddonsService {
{},
context
)
.pipe(
map((response) => {
return AddonMapper.fromAuthorizedAddonResponse(response as AuthorizedAddonGetResponseJsonApi);
})
);
.pipe(map((response) => AddonMapper.fromAuthorizedAddonResponse(response as AuthorizedAddonGetResponseJsonApi)));
}

getConfiguredAddons(addonType: string, referenceId: string): Observable<ConfiguredAddonModel[]> {
return this.jsonApiService
.get<
JsonApiResponse<ConfiguredAddonGetResponseJsonApi[], null>
>(`${this.apiUrl}/resource-references/${referenceId}/configured_${addonType}_addons/`)
.pipe(
map((response) => {
return response.data.map((item) => AddonMapper.fromConfiguredAddonResponse(item));
})
);
.pipe(map((response) => response.data.map((item) => AddonMapper.fromConfiguredAddonResponse(item))));
}

createAuthorizedAddon(
Expand Down
10 changes: 3 additions & 7 deletions src/app/shared/services/json-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import { JsonApiResponse } from '@osf/shared/models';
export class JsonApiService {
http: HttpClient = inject(HttpClient);

get<T>(url: string, params?: Record<string, unknown>): Observable<T> {
return this.http.get<T>(url, {
params: this.buildHttpParams(params),
});
get<T>(url: string, params?: Record<string, unknown>, context?: HttpContext): Observable<T> {
return this.http.get<T>(url, { params: this.buildHttpParams(params), context });
}

private buildHttpParams(params?: Record<string, unknown>): HttpParams {
Expand All @@ -38,9 +36,7 @@ export class JsonApiService {
}

post<T>(url: string, body?: unknown, params?: Record<string, unknown>): Observable<T> {
return this.http.post<T>(url, body, {
params: this.buildHttpParams(params),
});
return this.http.post<T>(url, body, { params: this.buildHttpParams(params) });
}

patch<T>(
Expand Down
Loading