aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/rest/rest-extractor.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/rest/rest-extractor.service.ts')
-rw-r--r--client/src/app/shared/rest/rest-extractor.service.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts
new file mode 100644
index 000000000..aa44799af
--- /dev/null
+++ b/client/src/app/shared/rest/rest-extractor.service.ts
@@ -0,0 +1,46 @@
1import { Injectable } from '@angular/core';
2import { Response } from '@angular/http';
3import { Observable } from 'rxjs/Observable';
4
5export interface ResultList {
6 data: any[];
7 total: number;
8}
9
10@Injectable()
11export class RestExtractor {
12
13 constructor () { ; }
14
15 extractDataBool(res: Response) {
16 return true;
17 }
18
19 extractDataList(res: Response) {
20 const body = res.json();
21
22 const ret: ResultList = {
23 data: body.data,
24 total: body.total
25 };
26
27 return ret;
28 }
29
30 extractDataGet(res: Response) {
31 return res.json();
32 }
33
34 handleError(res: Response) {
35 let text = 'Server error: ';
36 text += res.text();
37 let json = res.json();
38
39 const error = {
40 json,
41 text
42 };
43
44 return Observable.throw(error);
45 }
46}