Skip to content

Commit

Permalink
Update addable
Browse files Browse the repository at this point in the history
  • Loading branch information
bcameron1231 committed Nov 13, 2023
1 parent d4ad5e1 commit 755eace
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/graph/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import "@pnp/graph/list-items";
import "@pnp/graph/lists";

const graph = graphfi(...);
var version = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add("New Comment");
var version = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add({comment:"Test Comment", shouldCaptureMinorVersion: true});

```

Expand Down
51 changes: 8 additions & 43 deletions packages/graph/list-item/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ListItem as IListItemEntity, ListItemVersion as IListItemVersion, DocumentSetVersion as IDocumentSetVersionEntity } from "@microsoft/microsoft-graph-types";
import { _GraphCollection, graphInvokableFactory, _GraphInstance, IGraphCollection, GraphCollection, graphPost } from "../graphqueryable.js";
import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js";
import { body } from "@pnp/queryable";
import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById, addable, IAddable } from "../decorators.js";

/**
* Represents a list item entity
Expand All @@ -26,23 +25,10 @@ export const ListItem = graphInvokableFactory<IListItem>(_ListItem);
*/
@defaultPath("items")
@getById(ListItem)
export class _ListItems extends _GraphCollection<IListItemEntity[]>{
/**
* Create a new list item as specified in the request body.
*
* @param listItem a JSON representation of a List object.
*/
public async add(listItem: IListItemEntity): Promise<IListItemAddResult> {
const data = await graphPost(this, body(listItem));
@addable()
export class _ListItems extends _GraphCollection<IListItemEntity[]>{}

return {
data,
list: (<any>this).getById(data.id),
};
}
}

export interface IListItems extends _ListItems, IGetById<IListItem> { }
export interface IListItems extends _ListItems, IGetById<IListItem>, IAddable<IListItemEntity> { }
export const ListItems = graphInvokableFactory<IListItems>(_ListItems);

/**
Expand All @@ -67,34 +53,13 @@ export const DocumentSetVersion = graphInvokableFactory<IDocumentSetVersion>(_Do
*/
@defaultPath("documentSetVersions")
@getById(DocumentSetVersion)
export class _DocumentSetVersions extends _GraphCollection<IDocumentSetVersionEntity[]>{
/**
* Create a new document set version as specified in the request body.
*
* @param comment a comment about the captured version
* @param shouldCaptureMinorVersion If true, minor versions of items are also captured; otherwise, only major versions will be captured.
*
*/
public async add(comment: string, shouldCaptureMinorVersion = false): Promise<IDocumentSetVersionAddResult> {

const postBody = {
comment: comment,
shouldCaptureMinorVersion: shouldCaptureMinorVersion,
};
const data = await graphPost(this, body(postBody));

return {
data,
item: (<any>this).getById(data.id),
};
}
}

export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById<IDocumentSetVersion> {}
@addable()
export class _DocumentSetVersions extends _GraphCollection<IDocumentSetVersionEntity[]>{}
export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById<IDocumentSetVersion>, IAddable<IDocumentSetVersionEntity> {}
export const DocumentSetVersions = graphInvokableFactory<IDocumentSetVersions>(_DocumentSetVersions);

/**
* IListAddResult
* IDocumentSetVersionAddResult
*/
export interface IDocumentSetVersionAddResult {
item: IDocumentSetVersion;
Expand Down
6 changes: 3 additions & 3 deletions test/graph/list-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("List-Items", function () {
},
} as any);

return expect((itemAdded.data.id)).is.not.null;
return expect((itemAdded.id)).is.not.null;
}));

it("update", pnpTest("5766613a-51b8-4f88-ba0f-2436d160b86b", async function () {
Expand All @@ -82,7 +82,7 @@ describe("List-Items", function () {
title: getRandomString(5) + "Add",
},
} as any);
const r = await list.items.filter(`Id eq '${item.data.id}'`)();
const r = await list.items.filter(`Id eq '${item.id}'`)();
return expect(r.length).to.eq(0);
}));

Expand All @@ -99,7 +99,7 @@ describe("List-Items", function () {
}));

it.skip("documentSetVersions - add()", pnpTest("a192e096-fe84-4c2c-adc5-b1b9021c0031", async function () {
const documentSetVersion = await item.documentSetVersions.add("New Comment");
const documentSetVersion = await item.documentSetVersions.add({comment:"Test Comment"});
return expect(documentSetVersion).to.not.be.null && expect(documentSetVersion).to.haveOwnProperty("id");
}));

Expand Down

0 comments on commit 755eace

Please sign in to comment.