Skip to content

Commit 207b1aa

Browse files
Emmanuel De Saint StebanEmmanuel De Saint Steban
authored andcommitted
remove console.log
+ add new exemple
1 parent 474fca0 commit 207b1aa

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
/test-api/node_modules/
3+
/dist

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-http-annotations",
3-
"version": "0.5.2",
3+
"version": "0.6.1",
44
"main": "public_api.ts",
55
"files": [
66
"src"
@@ -26,7 +26,7 @@
2626
"@angular/platform-browser-dynamic": "6.0.3",
2727
"@angular/router": "6.0.3",
2828
"core-js": "^2.4.1",
29-
"ng-packagr": "^3.0.0",
29+
"ng-packagr": "^4.4.0",
3030
"rxjs": "^6.0.0-beta.1",
3131
"typescript": "2.7.2",
3232
"zone.js": "0.8.26"

src/ngx-http-annotations.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class HttpRestModule {
1515
}
1616

1717
export function onAppInit(http: HttpClient) {
18-
console.log('App Init : ', http, HttpRestUtils.http);
1918
return function () {
2019
HttpRestUtils.http = http;
2120
}

src/ngx-http-annotations.utils.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ export class HttpRestUtils {
5252
public static http: HttpClient = null;
5353

5454
public static decorate(decoratorName: string, annotations: any, ...args: any[]) {
55-
console.info ('decorate : ', decoratorName, annotations, args);
56-
switch (args.length) {
55+
switch (args.length) {
5756
case 1: {
5857
const [target] = args;
5958
HttpRestUtils.constructMetadata.apply(this, [ decoratorName, 'class', annotations, target.prototype ]);
@@ -88,7 +87,6 @@ export class HttpRestUtils {
8887
* @param entityData Entity extra data
8988
*/
9089
private static constructMetadata(metaName: string, entityType: ResourceMetadataType, value: any, target: any, entityData?: ExtraEntityData) {
91-
console.log('constructMetadata :', metaName, entityType, value, target, entityData);
9290

9391
target[RESOURSE_METADATA_ROOT] = target[RESOURSE_METADATA_ROOT] || {};
9492
target[RESOURSE_METADATA_ROOT][entityType] = target[RESOURSE_METADATA_ROOT][entityType] || {};
@@ -129,12 +127,10 @@ export class HttpRestUtils {
129127
responseType: producesType,
130128
observe
131129
};
132-
console.log('before request ', requestMethodName, url, params);
133130
let request = HttpRestUtils.http.request(requestMethodName, url, params);
134131

135132
const responseIndex = HttpRestUtils.collectResponseIndex(target, key, args);
136133

137-
console.warn('responseIndex : ', responseIndex, args);
138134
if (responseIndex >= 0) {
139135
const newArgs = args;
140136
if (args.length > responseIndex) {
@@ -143,12 +139,10 @@ export class HttpRestUtils {
143139
newArgs.splice(responseIndex, 0, request);
144140
}
145141

146-
console.warn('call orininal function : ', newArgs);
147142
return originalFunction(...newArgs);
148143
}
149144

150145
return request;
151-
// return HttpRestUtils.http.request(requestMethodName, url);
152146
};
153147
};
154148
}
@@ -252,11 +246,7 @@ export class HttpRestUtils {
252246
: {};
253247
const mergedHeaders = Object.assign({}, classHeaders, methodHeaders);
254248

255-
/*const httpHeaders = new HttpHeaders();
256-
for (const header in mergedHeaders) {
257-
httpHeaders.append(header, mergedHeaders[header]);
258-
}
259-
return httpHeaders;*/
249+
260250
return mergedHeaders;
261251
}
262252
}

test-api/src/app/app.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ <h3>Post 4 (Update)</h3>
1717
<h3>Post 5 (Delete)</h3>
1818
{{post5 | json}}
1919

20+
<h3>todos (with rxjs filter)</h3>
21+
{{todos | json}}
22+

test-api/src/app/app.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class AppComponent implements OnInit {
1414
public post3: any;
1515
public post4: any;
1616
public post5: any;
17+
public todos: any;
1718

1819
constructor(private api: ApiService) {}
1920

@@ -41,8 +42,12 @@ export class AppComponent implements OnInit {
4142
this.post5 = post;
4243
});
4344

44-
}
45-
);
45+
});
46+
47+
this.api.getTodosNotDone().subscribe((todos)=> {
48+
console.log('todos :', todos);
49+
this.todos = todos;
50+
});
4651
}
4752

4853

test-api/src/app/services/api.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
PUT,
1212
DELETE
1313
} from '../../../../public_api';
14-
import {HttpClient} from "@angular/common/http";
15-
import {from, Observable} from "rxjs";
16-
import {flatMap, map, mergeAll, take, tap} from 'rxjs/operators';
14+
import {HttpClient} from '@angular/common/http';
15+
import {from, Observable} from 'rxjs';
16+
import {flatMap, map, mergeAll, take, tap, filter} from 'rxjs/operators';
1717

1818
@Injectable({
1919
providedIn: 'root'
@@ -69,5 +69,13 @@ export class ApiService {
6969
return null;
7070
}
7171

72+
@GET
73+
@Path('todos')
74+
public getTodosNotDone(@ResponseObservable res: Observable<any> = undefined): Observable<any> {
75+
//return this.http.request('GET', 'https://jsonplaceholder.typicode.com/todos');
76+
return res.pipe(
77+
map(todos => todos.filter(todo => !todo.completed)));
78+
}
79+
7280

7381
}

0 commit comments

Comments
 (0)