This repository was archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathquery.js
More file actions
75 lines (75 loc) · 2.38 KB
/
query.js
File metadata and controls
75 lines (75 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"use strict";
const Rx_1 = require('rxjs/Rx');
const operation_1 = require('./operation');
class PagedResult {
}
exports.PagedResult = PagedResult;
class ODataQuery extends operation_1.ODataOperation {
constructor(_typeName, config, http) {
super(_typeName, config, http);
}
Filter(filter) {
this._filter = filter;
return this;
}
;
Top(top) {
this._top = top;
return this;
}
;
Skip(skip) {
this._skip = skip;
return this;
}
OrderBy(orderBy) {
this._orderBy = orderBy;
return this;
}
Exec() {
let params = this.getQueryParams();
let config = this.config;
return this.http.get(this.buildResourceURL(), { search: params, headers: this.config.requestOptions.headers })
.map(res => this.extractArrayData(res, config))
.catch((err, caught) => {
if (this.config.handleError)
this.config.handleError(err, caught);
return Rx_1.Observable.throw(err);
});
}
ExecWithCount() {
let params = this.getQueryParams();
params.set('$count', 'true'); // OData v4 only
let config = this.config;
return this.http.get(this.buildResourceURL(), { search: params, headers: this.config.requestOptions.headers })
.map(res => this.extractArrayDataWithCount(res, config))
.catch((err, caught) => {
if (this.config.handleError)
this.config.handleError(err, caught);
return Rx_1.Observable.throw(err);
});
}
buildResourceURL() {
return this.config.baseUrl + '/' + this._typeName + '/';
}
getQueryParams() {
let params = super.getParams();
if (this._filter)
params.set(this.config.keys.filter, this._filter);
if (this._top)
params.set(this.config.keys.top, this._top.toString());
if (this._skip)
params.set(this.config.keys.skip, this._skip.toString());
if (this._orderBy)
params.set(this.config.keys.orderBy, this._orderBy);
return params;
}
extractArrayData(res, config) {
return config.extractQueryResultData(res);
}
extractArrayDataWithCount(res, config) {
return config.extractQueryResultDataWithCount(res);
}
}
exports.ODataQuery = ODataQuery;
//# sourceMappingURL=query.js.map