Skip to content

Commit

Permalink
Add getDmsObjectNotes() function in DMS SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
andinaetherk3 committed Oct 12, 2023
1 parent c477909 commit 089029e
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { DvelopContext } from "@dvelop-sdk/core";
import {
_getDmsObjectNotesDefaultTransformFunction,
_getDmsObjectNotesFactory, DmsObjectNotes,
GetDmsObjectNotesParams
} from "./get-dms-object-notes";
import { HttpResponse } from "../../utils/http";

describe("getDmsObjectNotes", () => {
let mockHttpRequestFunction = jest.fn();
let mockTransformFunction = jest.fn();

let context: DvelopContext;
let params: GetDmsObjectNotesParams;

beforeEach(() => {
jest.resetAllMocks();

context = {
systemBaseUri: "HiItsMeSystemBaseUri"
};

params = {
repositoryId: "HiItsMeRepositoryId",
dmsObjectId: "HiItsMeDmsObjectId"
};
});

it("should make correct request", async () => {
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, mockTransformFunction);
await getDmsObjectNotes(context, params);

expect(mockHttpRequestFunction).toHaveBeenCalledTimes(1);
expect(mockHttpRequestFunction).toHaveBeenCalledWith(context, {
method: "GET",
url: "/dms",
follows: ["repo", "dmsobjectwithmapping", "notes"],
templates: {
"repositoryid": params.repositoryId,
"dmsobjectid": params.dmsObjectId
}
});
});

it("should pass response to transform and return transform-result", async () => {
const response: HttpResponse = { data: {
notes: [{
creator: {
id: "HiItsMeCreatorId",
displayName: "HiItsMeCreatorDisplayName"
},
text: "HiItsMeText",
created: "2023-10-11T09:09:09.453+02:00"
}]
} } as HttpResponse;

const transformResult: DmsObjectNotes = {
repositoryId: "HiItsMeRepositoryId",
dmsObjectId: "HiItsMeDmsObjectId",
notes: [{
creator: {
id: "HiItsMeCreatorId",
displayName: "HiItsMeCreatorDisplayName"
},
text: "HiItsMeText",
created: new Date("2023-10-11T09:09:09.453+02:00")
}]
};

mockHttpRequestFunction.mockResolvedValue(response);
mockTransformFunction.mockReturnValue(transformResult);

const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, mockTransformFunction);
await getDmsObjectNotes(context, params);

expect(mockTransformFunction).toHaveBeenCalledTimes(1);
expect(mockTransformFunction).toHaveBeenCalledWith(response, context, params);
});

describe("getDmsObjectNotesDefaultTransformFunction", () => {
it("should return response DmsObjectNotes with single note", async () => {
const response: HttpResponse = { data: {
notes: [{
creator: {
id: "HiItsMeCreatorId",
displayName: "HiItsMeCreatorDisplayName"
},
text: "HiItsMeText",
created: "2023-10-11T09:09:09.453+02:00"
}]
} } as HttpResponse;

const expectedResult: DmsObjectNotes = {
repositoryId: "HiItsMeRepositoryId",
dmsObjectId: "HiItsMeDmsObjectId",
notes: [{
creator: {
id: "HiItsMeCreatorId",
displayName: "HiItsMeCreatorDisplayName"
},
text: "HiItsMeText",
created: new Date("2023-10-11T09:09:09.453+02:00")
}]
};

mockHttpRequestFunction.mockResolvedValue(response);
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, _getDmsObjectNotesDefaultTransformFunction);
const result = await getDmsObjectNotes(context, params);

expect(result).toEqual(expectedResult);
});

it("should return response DmsObjectNotes without notes when dmsObject has no notes", async () => {
const response: HttpResponse = { data: {
notes: []
} } as HttpResponse;

const expectedResult: any = {
repositoryId: "HiItsMeRepositoryId",
dmsObjectId: "HiItsMeDmsObjectId",
notes: []
};

mockHttpRequestFunction.mockResolvedValue(response);
const getDmsObjectNotes = _getDmsObjectNotesFactory(mockHttpRequestFunction, _getDmsObjectNotesDefaultTransformFunction);
const result = await getDmsObjectNotes(context, params);

expect(result).toEqual(expectedResult);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { _defaultHttpRequestFunction, HttpConfig, HttpResponse } from "../../utils/http";
import { DvelopContext } from "../../index";

/**
* Parameters for the {@link getDmsObjectNotes}-function.
* @category DmsObject
*/
export interface GetDmsObjectNotesParams {
/** ID of the repository */
repositoryId: string;
/** ID of the DmsObject */
dmsObjectId: string;
}

/**
* Result type for the {@link getDmsObjectNotes}-function.
* @category DmsObject
*/
export interface DmsObjectNotes {
/** ID of the repository */
repositoryId: string;
/** ID of the DmsObject */
dmsObjectId: string;
/* Notes of the DmsObject */
notes: SingleDmsObjectNote[];
}

/**
* All information provided for a single note for the {@link DmsObjectNotes}-interface.
* @category DmsObject
*/
export interface SingleDmsObjectNote {
/* Creator of the DmsObjectNotes */
creator: {
/* ID of the creator of the note */
id: string;
/* DisplayName is the full name of the creator */
displayName: string;
},
/* Text of the note */
text: string;
/* Creation date of the note */
created: Date;
}

/**
* Default transform-function provided to the {@link getDmsObjectNotes}-function. See [Advanced Topics](https://github.com/d-velop/dvelop-sdk-node#advanced-topics) for more information.
* @internal
* @category DmsObject
*/
export function _getDmsObjectNotesDefaultTransformFunction(response: HttpResponse<any>, context: DvelopContext, params: GetDmsObjectNotesParams) {
let responseNotes = response.data.notes;

if (responseNotes === undefined || responseNotes === null) {
responseNotes = [];
}

const mappedNotes = responseNotes.map((note: SingleDmsObjectNote) => {
return {
creator: {
id: note.creator.id,
displayName: note.creator.displayName
},
text: note.text,
created: new Date(note.created)
};
});

return {
repositoryId: params.repositoryId,
dmsObjectId: params.dmsObjectId,
notes: mappedNotes
};
}

/**
* Factory for the {@link getDmsObjectNotes}-function. See [Advanced Topics](https://github.com/d-velop/dvelop-sdk-node#advanced-topics) for more information.
* @typeparam T Return type of the {@link getDmsObjectNotes}-function. A corresponding transformFunction has to be supplied.
* @category DmsObject
*/
export function _getDmsObjectNotesFactory<T>(
httpRequestFunction: (context: DvelopContext, config: HttpConfig) => Promise<HttpResponse>,
transformFunction: (response: HttpResponse, context: DvelopContext, params: GetDmsObjectNotesParams) => T
): (context: DvelopContext, params: GetDmsObjectNotesParams) => Promise<T> {
return async (context: DvelopContext, params: GetDmsObjectNotesParams) => {
const response: HttpResponse = await httpRequestFunction(context, {
method: "GET",
url: "/dms",
follows: ["repo", "dmsobjectwithmapping", "notes"],
templates: {
"repositoryid": params.repositoryId,
"dmsobjectid": params.dmsObjectId
}
});

return transformFunction(response, context, params);
};
}

/**
* Get all notes for an existing DmsObject.
*
* ```typescript
* import { getDmsObjectNotes } from "@dvelop-sdk/dms";
*
* await createDmsObjectNote({
* systemBaseUri: "https://steamwheedle-cartel.d-velop.cloud",
* authSessionId: "dQw4w9WgXcQ"
* }, {
* repositoryId: "qnydFmqHuVo",
* dmsObjectId: "GDYQ3PJKrT8"
* });
* ```
*
* @category DmsObject
*/
/* istanbul ignore next */
export async function getDmsObjectNotes(context: DvelopContext, params: GetDmsObjectNotesParams): Promise<DmsObjectNotes> {
return await _getDmsObjectNotesFactory(_defaultHttpRequestFunction, _getDmsObjectNotesDefaultTransformFunction)(context, params);
}
1 change: 1 addition & 0 deletions packages/dms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export { getRepositories } from "./repositories/get-repositories/get-repositorie
// DmsObjects
export { GetDmsObjectParams, DmsObject, getDmsObject } from "./dms-objects/get-dms-object/get-dms-object";
export { getDmsObjectMainFile, getDmsObjectPdfFile } from "./dms-objects/get-dms-object-file/get-dms-object-file";
export { GetDmsObjectNotesParams, DmsObjectNotes, SingleDmsObjectNote, getDmsObjectNotes } from "./dms-objects/get-dms-object-notes/get-dms-object-notes";
export { CreateDmsObjectParams, createDmsObject } from "./dms-objects/create-dms-object/create-dms-object";
export { CreateDmsObjectNoteParams, createDmsObjectNote as createDmsObjectNotes } from "./dms-objects/create-dms-object-note/create-dms-object-note";
export { StoreFileTemporarilyParams, storeFileTemporarily } from "./dms-objects/store-file-temporarily/store-file-temporarily";
Expand Down
3 changes: 2 additions & 1 deletion packages/dms/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export { _getRepositoriesFactory, _getRepositoriesDefaultTransformFunction } fro
// DmsObjects
export { _getDmsObjectFactory, _getDmsObjectDefaultTransformFunction, _getDmsObjectDefaultTransformFunctionFactory } from "./dms-objects/get-dms-object/get-dms-object";
export { _getDmsObjectMainFileFactory, _getDmsObjectPdfFileFactory } from "./dms-objects/get-dms-object-file/get-dms-object-file";
export { _getDmsObjectNotesFactory, _getDmsObjectNotesDefaultTransformFunction } from "./dms-objects/get-dms-object-notes/get-dms-object-notes";
export { _createDmsObjectDefaultStoreFileFunction, _createDmsObjectDefaultTransformFunction } from "./dms-objects/create-dms-object/create-dms-object";
export { _createDmsObjectNoteFactory, _createDmsObjectNoteDefaultTransformFunction } from "./dms-objects/create-dms-object-note/create-dms-object-note"
export { _createDmsObjectNoteFactory, _createDmsObjectNoteDefaultTransformFunction } from "./dms-objects/create-dms-object-note/create-dms-object-note";
export { _storeFileTemporarilyFactory, _storeFileTemporarilyDefaultTransformFunction } from "./dms-objects/store-file-temporarily/store-file-temporarily";
export { _updateDmsObjectFactory, _updateDmsObjectDefaultTransformFunction } from "./dms-objects/update-dms-object/update-dms-object";
export { _updateDmsObjectStatusFactory, _updateDmsObjectStatusDefaultTransformFunction } from "./dms-objects/update-dms-object-status/update-dms-object-status";
Expand Down

0 comments on commit 089029e

Please sign in to comment.