Skip to content

Commit bfddcf9

Browse files
authored
Update webapi.ts
1 parent 50784ae commit bfddcf9

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/dataverse-webapi/src/webapi.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ function handleError(result: string): unknown {
103103
return new Error('Unexpected Error');
104104
}
105105
}
106-
107106
/**
108107
* Retrieve a record from Dataverse
109108
* @param apiConfig WebApiConfig object
@@ -119,14 +118,32 @@ export function retrieve(
119118
submitRequest: RequestCallback,
120119
queryString?: string,
121120
queryOptions?: QueryOptions
121+
): Promise<Entity> {
122+
id = parseGuid(id);
123+
return retrieveByKey(apiConfig, entitySet, id, submitRequest, queryString, queryOptions);
124+
}
125+
/**
126+
* Retrieve a record from Dataverse
127+
* @param apiConfig WebApiConfig object
128+
* @param entitySet Type of entity to retrieve
129+
* @param id Id of record to retrieve
130+
* @param queryString OData query string parameters
131+
* @param queryOptions Various query options for the query
132+
*/
133+
export function retrieveByKey(
134+
apiConfig: WebApiConfig,
135+
entitySet: string,
136+
key: string,
137+
submitRequest: RequestCallback,
138+
queryString?: string,
139+
queryOptions?: QueryOptions
122140
): Promise<Entity> {
123141
if (queryString != null && !/^[?]/.test(queryString)) {
124142
queryString = `?${queryString}`;
125143
}
126144

127-
id = parseGuid(id);
128145

129-
const query: string = queryString != null ? `${entitySet}(${id})${queryString}` : `${entitySet}(${id})`;
146+
const query: string = queryString != null ? `${entitySet}(${key})${queryString}` : `${entitySet}(${key})`;
130147

131148
const config = {
132149
method: 'GET',

0 commit comments

Comments
 (0)