From 755eacef4b5515017ff7e5f330a154809d2b4229 Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Mon, 13 Nov 2023 07:56:53 -0500 Subject: [PATCH] Update addable --- docs/graph/items.md | 2 +- packages/graph/list-item/types.ts | 51 +++++-------------------------- test/graph/list-items.ts | 6 ++-- 3 files changed, 12 insertions(+), 47 deletions(-) diff --git a/docs/graph/items.md b/docs/graph/items.md index 6401e7a0b..21eab2757 100644 --- a/docs/graph/items.md +++ b/docs/graph/items.md @@ -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}); ``` diff --git a/packages/graph/list-item/types.ts b/packages/graph/list-item/types.ts index 62af34f61..101734540 100644 --- a/packages/graph/list-item/types.ts +++ b/packages/graph/list-item/types.ts @@ -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 @@ -26,23 +25,10 @@ export const ListItem = graphInvokableFactory(_ListItem); */ @defaultPath("items") @getById(ListItem) -export class _ListItems extends _GraphCollection{ - /** - * 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 { - const data = await graphPost(this, body(listItem)); +@addable() +export class _ListItems extends _GraphCollection{} - return { - data, - list: (this).getById(data.id), - }; - } -} - -export interface IListItems extends _ListItems, IGetById { } +export interface IListItems extends _ListItems, IGetById, IAddable { } export const ListItems = graphInvokableFactory(_ListItems); /** @@ -67,34 +53,13 @@ export const DocumentSetVersion = graphInvokableFactory(_Do */ @defaultPath("documentSetVersions") @getById(DocumentSetVersion) -export class _DocumentSetVersions extends _GraphCollection{ - /** - * 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 { - - const postBody = { - comment: comment, - shouldCaptureMinorVersion: shouldCaptureMinorVersion, - }; - const data = await graphPost(this, body(postBody)); - - return { - data, - item: (this).getById(data.id), - }; - } -} - -export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById {} +@addable() +export class _DocumentSetVersions extends _GraphCollection{} +export interface IDocumentSetVersions extends _DocumentSetVersions, IGetById, IAddable {} export const DocumentSetVersions = graphInvokableFactory(_DocumentSetVersions); /** - * IListAddResult + * IDocumentSetVersionAddResult */ export interface IDocumentSetVersionAddResult { item: IDocumentSetVersion; diff --git a/test/graph/list-items.ts b/test/graph/list-items.ts index 9f134b60b..b0d4d5b4f 100644 --- a/test/graph/list-items.ts +++ b/test/graph/list-items.ts @@ -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 () { @@ -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); })); @@ -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"); }));