-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathodata-get-all-request-config.ts
61 lines (57 loc) · 1.82 KB
/
odata-get-all-request-config.ts
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
import { EntityBase, Constructable } from '../entity';
import { Filterable } from '../filter';
import { Orderable } from '../order';
import { Selectable } from '../selectable';
import { Expandable } from '../expandable';
import { ODataUri } from '../uri-conversion';
import { ODataRequestConfig } from './odata-request-config';
import { WithGetAllRestrictions } from './odata-request-traits';
/**
* OData getAll request configuration for an entity type.
*
* @typeparam EntityT - Type of the entity to setup a request for
*/
export class ODataGetAllRequestConfig<EntityT extends EntityBase>
extends ODataRequestConfig
implements WithGetAllRestrictions<EntityT> {
top: number;
skip: number;
filter: Filterable<EntityT>;
orderBy: Orderable<EntityT>[];
selects: Selectable<EntityT>[];
expands: Expandable<EntityT>[];
/**
* Creates an instance of ODataGetAllRequestConfig.
*
* @param entityConstructor - Constructor type of the entity to create a configuration for
*/
constructor(
readonly entityConstructor: Constructable<EntityT>,
private oDataUri: ODataUri
) {
super('get', entityConstructor._defaultServicePath);
}
resourcePath(): string {
return this.entityConstructor._entityName;
}
queryParameters(): Record<string, any> {
const params: Record<string, any> = {
format: 'json',
...this.oDataUri.getSelect(this.selects),
...this.oDataUri.getExpand(
this.selects,
this.expands,
this.entityConstructor
),
...this.oDataUri.getFilter(this.filter, this.entityConstructor),
...this.oDataUri.getOrderBy(this.orderBy)
};
if (typeof this.top !== 'undefined') {
params.top = this.top;
}
if (typeof this.skip !== 'undefined') {
params.skip = this.skip;
}
return this.prependDollarToQueryParameters(params);
}
}