|
1 | 1 | import { Injectable } from '@angular/core'; |
2 | 2 | import { Observable } from 'rxjs'; |
3 | 3 | import { HttpClient, HttpParams, HttpHeaders } from "@angular/common/http"; |
| 4 | +import { HttpObserve } from "@angular/common/http/src/client"; |
4 | 5 |
|
5 | 6 | interface httpRequestOptions { |
6 | 7 | body?: any; |
7 | 8 | headers?: HttpHeaders; |
8 | 9 | params?: HttpParams; |
| 10 | + observe?: HttpObserve; |
9 | 11 | reportProgress?: boolean; |
10 | 12 | responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; |
11 | 13 | withCredentials?: boolean; |
12 | 14 | } |
13 | 15 |
|
| 16 | + |
| 17 | +export function observe(annotations: any) { |
| 18 | + return (...args: any[]) => HttpRestUtils.decorate.apply(this, ['observe', annotations, ...args]); |
| 19 | +} |
14 | 20 | export function path(annotations: any) { |
15 | 21 | return (...args: any[]) => HttpRestUtils.decorate.apply(this, ['path', annotations, ...args]); |
16 | 22 | } |
@@ -103,17 +109,27 @@ export class HttpRestUtils { |
103 | 109 | const search = HttpRestUtils.collectQueryParams(target, key, args); |
104 | 110 | const headers = HttpRestUtils.collectHeaders(target, key, args); |
105 | 111 | const producesType = HttpRestUtils.produce(target, key, args); |
| 112 | + const observe = HttpRestUtils.getObserve(target, key, args) |
106 | 113 | const params: httpRequestOptions = { |
107 | 114 | body, |
108 | 115 | params: search, |
109 | 116 | headers, |
110 | | - responseType: producesType |
| 117 | + responseType: producesType, |
| 118 | + observe |
111 | 119 | }; |
112 | 120 | return HttpRestUtils.http.request(requestMethodName, url, params); |
113 | 121 | }; |
114 | 122 | }; |
115 | 123 | } |
116 | 124 |
|
| 125 | + private static getObserve(target: any, methodName: string, args: any[]) { |
| 126 | + if (target[RESOURSE_METADATA_ROOT].methods |
| 127 | + && target[RESOURSE_METADATA_ROOT].methods[methodName]) { |
| 128 | + return target[RESOURSE_METADATA_ROOT].methods[methodName].observe; |
| 129 | + } |
| 130 | + return undefined; |
| 131 | + } |
| 132 | + |
117 | 133 | private static produce(target: any, methodName: string, args: any[]) { |
118 | 134 | if (target[RESOURSE_METADATA_ROOT].methods |
119 | 135 | && target[RESOURSE_METADATA_ROOT].methods[methodName]) { |
|
0 commit comments