Skip to content

Commit 9cf728d

Browse files
add creteAttribute module
1 parent ef908f7 commit 9cf728d

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

src/dynamics-web-api.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
count,
1111
countAll,
1212
create,
13+
createAttribute,
1314
createEntity,
1415
deleteRecord,
1516
disassociate,
@@ -277,19 +278,7 @@ export class DynamicsWebApi {
277278
* @param request - An object that represents all possible options for a current request.
278279
* @returns {Promise} D365 Web Api Response
279280
*/
280-
createAttribute = <T = any>(request: CreateAttributeRequest): Promise<T> => {
281-
ErrorHelper.parameterCheck(request, "DynamicsWebApi.createAttribute", "request");
282-
ErrorHelper.parameterCheck(request.data, "DynamicsWebApi.createAttribute", "request.data");
283-
ErrorHelper.keyParameterCheck(request.entityKey, "DynamicsWebApi.createAttribute", "request.entityKey");
284-
285-
const internalRequest = copyRequest(request);
286-
internalRequest.collection = "EntityDefinitions";
287-
internalRequest.functionName = "retrieveEntity";
288-
internalRequest.navigationProperty = "Attributes";
289-
internalRequest.key = request.entityKey;
290-
291-
return this.create(<CreateRequest>internalRequest);
292-
};
281+
createAttribute = <T = any>(request: CreateAttributeRequest): Promise<T> => createAttribute(request, this.#client);
293282

294283
/**
295284
* Sends an asynchronous request to update an attribute.

src/requests/downloadFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { InternalRequest } from "../types";
55
import { convertToFileBuffer, copyRequest, downloadChunkSize } from "../utils/Utility";
66
import { LIBRARY_NAME } from "./constants";
77

8-
const FUNCTION_NAME = "deleteRecord";
8+
const FUNCTION_NAME = "downloadFile";
99
const REQUEST_NAME = `${LIBRARY_NAME}.${FUNCTION_NAME}`;
1010

1111
const downloadFileChunk = async (

src/requests/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ export * from "./downloadFile";
2323
export * from "./metadata/createEntity";
2424
export * from "./metadata/updateEntity";
2525
export * from "./metadata/retrieveEntity";
26-
export * from "./metadata/retrieveEntities";
26+
export * from "./metadata/retrieveEntities";
27+
export * from "./metadata/createAttribute";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { IDataverseClient } from "../../client/dataverse";
2+
import type { CreateAttributeRequest, CreateRequest } from "../../dynamics-web-api";
3+
import { copyRequest } from "../../utils/Utility";
4+
import { create } from "../create";
5+
import { LIBRARY_NAME } from "../constants";
6+
import { ErrorHelper } from "../../helpers/ErrorHelper";
7+
8+
const FUNCTION_NAME = "createAttribute";
9+
const REQUEST_NAME = `${LIBRARY_NAME}.${FUNCTION_NAME}`;
10+
11+
export const createAttribute = <T = any>(request: CreateAttributeRequest, client: IDataverseClient): Promise<T> => {
12+
ErrorHelper.parameterCheck(request, REQUEST_NAME, "request");
13+
ErrorHelper.parameterCheck(request.data, REQUEST_NAME, "request.data");
14+
ErrorHelper.keyParameterCheck(request.entityKey, REQUEST_NAME, "request.entityKey");
15+
16+
const internalRequest = copyRequest(request);
17+
internalRequest.collection = "EntityDefinitions";
18+
internalRequest.functionName = FUNCTION_NAME;
19+
internalRequest.navigationProperty = "Attributes";
20+
internalRequest.key = request.entityKey;
21+
22+
return create(internalRequest as CreateRequest, client);
23+
};

0 commit comments

Comments
 (0)