mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[AAE-12501] Create a request options interface with the needed props, remove the import from js-api, return the body from request
This commit is contained in:
@@ -20,3 +20,4 @@ export * from './lib/api-clients.service';
|
||||
export * from './lib/clients';
|
||||
export * from './lib/types';
|
||||
export * from './lib/adf-http-client.service';
|
||||
export * from './lib/interfaces';
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { SHOULD_ADD_AUTH_TOKEN } from '@alfresco/adf-core/auth';
|
||||
import { Emitters as JsApiEmitters, HttpClient as JsApiHttpClient, RequestOptions, SecurityOptions, isBrowser } from '@alfresco/js-api';
|
||||
import { Emitters as JsApiEmitters, HttpClient as JsApiHttpClient, SecurityOptions, isBrowser } from '@alfresco/js-api';
|
||||
import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, of, Subject, throwError } from 'rxjs';
|
||||
@@ -25,6 +25,7 @@ import { convertObjectToFormData, getQueryParamsWithCustomEncoder, isBlobRespons
|
||||
import { AlfrescoApiParamEncoder } from './alfresco-api/alfresco-api.param-encoder';
|
||||
import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error';
|
||||
import { Constructor } from './types';
|
||||
import { RequestOptions } from './interfaces';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -35,7 +36,6 @@ export class AdfHttpClient implements JsApiHttpClient {
|
||||
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
|
||||
|
||||
request<T = any>(url: string, options: RequestOptions, sc: SecurityOptions = this.defaultSecurityOptions, emitters?: JsApiEmitters): Promise<T> {
|
||||
const body = AdfHttpClient.getBody(options);
|
||||
const params = getQueryParamsWithCustomEncoder(options.queryParams, new AlfrescoApiParamEncoder());
|
||||
@@ -61,7 +61,7 @@ export class AdfHttpClient implements JsApiHttpClient {
|
||||
if(emitters){
|
||||
return this.requestWithLegacyEventEmitters<T>(request, emitters, options.returnType);
|
||||
}
|
||||
return request.toPromise<T>();
|
||||
return request.pipe(map(req => req.body)).toPromise<T>();
|
||||
}
|
||||
|
||||
post<T = any>(url: string, options: RequestOptions, sc?: SecurityOptions, emitters?: JsApiEmitters): Promise<T> {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export interface RequestOptions {
|
||||
httpMethod?: string;
|
||||
queryParams?: any;
|
||||
headerParams?: any;
|
||||
formParams?: any;
|
||||
bodyParam?: any;
|
||||
returnType?: any;
|
||||
responseType?: string;
|
||||
readonly accept?: string;
|
||||
readonly contentType?: string;
|
||||
}
|
||||
@@ -34,20 +34,16 @@ export class OAuth2Service {
|
||||
constructor(private adfHttpClient: AdfHttpClient) {}
|
||||
|
||||
request<T>(opts: OAuth2RequestParams): Observable<T> {
|
||||
const { httpMethod, url, bodyParam, pathParams, queryParams } = opts;
|
||||
const { httpMethod, url, bodyParam, queryParams } = opts;
|
||||
return from(
|
||||
this.adfHttpClient.request(
|
||||
url,
|
||||
{
|
||||
path: url,
|
||||
httpMethod,
|
||||
pathParams,
|
||||
queryParams,
|
||||
headerParams: {},
|
||||
formParams: {},
|
||||
bodyParam,
|
||||
contentTypes: JSON_TYPE,
|
||||
accepts: JSON_TYPE,
|
||||
returnType: Object
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user