-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathodata-update-request-config.ts
55 lines (48 loc) · 1.45 KB
/
odata-update-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
/* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. */
import { EntityBase, Constructable } from '../entity';
import { FieldType } from '../selectable';
import { ODataUri } from '../uri-conversion';
import { ODataRequestConfig } from './odata-request-config';
import { WithKeys, WithETag } from './odata-request-traits';
/**
* OData update request configuration for an entity type.
*
* @typeparam EntityT - Type of the entity to setup a request for
*/
export class ODataUpdateRequestConfig<EntityT extends EntityBase>
extends ODataRequestConfig
implements WithKeys, WithETag {
keys: Record<string, FieldType>;
eTag: string;
versionIdentifierIgnored = false;
/**
* Creates an instance of ODataUpdateRequestConfig.
*
* @param _entityConstructor - Constructor type of the entity to create a configuration for
*/
constructor(
readonly _entityConstructor: Constructable<EntityT>,
private oDataUri: ODataUri
) {
super(
UpdateStrategy.MODIFY_WITH_PATCH,
_entityConstructor._defaultServicePath
);
}
resourcePath(): string {
return this.oDataUri.getResourcePathForKeys(
this.keys,
this._entityConstructor
);
}
queryParameters(): Record<string, any> {
return this.prependDollarToQueryParameters({});
}
updateWithPut(): void {
this.method = UpdateStrategy.REPLACE_WITH_PUT;
}
}
enum UpdateStrategy {
MODIFY_WITH_PATCH = 'patch',
REPLACE_WITH_PUT = 'put'
}