Skip to content

Commit

Permalink
v4- Graph Items Docs Update and Document Set Versions
Browse files Browse the repository at this point in the history
WIP - Initial check-in
  • Loading branch information
bcameron1231 committed Oct 3, 2023
1 parent d23039a commit fcb2fac
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 12 deletions.
105 changes: 93 additions & 12 deletions docs/graph/items.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,119 @@
# @pnp/graph/items

Currently, there is no module in graph to access all items directly. Please, instead, default to search by path using the following methods.

[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md)

### Get list items

```TypeScript
import { Site } from "@pnp/graph/sites";
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";

const sites = graph.sites.getById("{site id}");
const graph = graphfi(...);
const items = const siteLists = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items();

const items = await Site(sites, "lists/{listid}/items")();
```

### Get File/Item version information

```TypeScript
import { Site } from "@pnp/graph/sites";

const sites = graph.sites.getById("{site id}");
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";

const users = await Site(sites, "lists/{listid}/items/{item id}/versions")();
const graph = graphfi(...);
const itemVersions = const siteLists = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items.getById(1).versions();

```

### Get list items with fields included

```TypeScript
import { Site } from "@pnp/graph/sites";
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";

const graph = graphfi(...);
const listItems = await graph.site.getById("{site identifier}").lists.getById("{list identifier}").items..expand("fields")();

```

### Create a new list item

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";

const sites = graph.sites.getById("{site id}");
const graph = graphfi(...);
var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.add({
Title: "Widget",
});

```
### Update a list item

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";

const graph = graphfi(...);
var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").update({
Title: "Widget",
});

```

### Delete a list item

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";

const graph = graphfi(...);
var newItem = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").delete();

```

### Get Document Set Versions of an Item

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";
import "@pnp/graph/documentSetVersions";
const graph = graphfi(...);
var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}")();
var documentSetVersions = item.documentSetVersions();

```

### Create a new Document Set Version

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";
import "@pnp/graph/documentSetVersions";

const graph = graphfi(...);
var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.add("New Comment");

```

### Restore a Document Set version

```TypeScript
import { graphfi } from "@pnp/graph";
import "@pnp/graph/list-items";
import "@pnp/graph/lists";
import "@pnp/graph/documentSetVersions";

const listItems : IList[] = await Site(sites, "lists/{site id}/items?$expand=fields")();
const graph = graphfi(...);
var item = await graph.sites.getById("{site identifier}").lists.getById("{list identifier}").items.getById("{item identifier}").documentSetVersions.getById(1).restore();

```

#### Hint: Note that you can just use normal [graph queries](https://developer.microsoft.com/en-us/graph/graph-explorer) in this search.
10 changes: 10 additions & 0 deletions packages/graph/documentSetVersions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import "./list-item.js";
export {
IDocumentSetVersion,
DocumentSetVersion,
IDocumentSetVersions,
DocumentSetVersions,
IDocumentSetVersionAddResult
} from "./types.js";

14 changes: 14 additions & 0 deletions packages/graph/documentSetVersions/list-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { addProp } from "@pnp/queryable";
import { DocumentSetVersions, IDocumentSetVersions } from "./types.js";
import { _ListItem } from "../list-item/types.js";

declare module "../list-item/types" {
interface _ListItem {
readonly documentSetVersions: IDocumentSetVersions;
}
interface IListItem {
readonly documentSetVersions: IDocumentSetVersions;
}
}

addProp(_ListItem, "documentSetVersions", DocumentSetVersions);
60 changes: 60 additions & 0 deletions packages/graph/documentSetVersions/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { DocumentSetVersion as IDocumentSetVersionEntity } from "@microsoft/microsoft-graph-types";
import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost, GraphInstance, GraphQueryable } from "../graphqueryable.js";
import { defaultPath, deleteable, IDeleteable, getById, IGetById } from "../decorators.js";
import { body } from "@pnp/queryable";

/**
* Represents a document set version
*/
@deleteable()
export class _DocumentSetVersion extends _GraphInstance<IDocumentSetVersionEntity> {
/**
* Restore a document set version
*
*/
public async restore(): Promise<void> {
return graphPost(DocumentSetVersion(this, "restore"));
}
}
export interface IDocumentSetVersion extends _DocumentSetVersion, IDeleteable { }
export const DocumentSetVersion = graphInvokableFactory<IDocumentSetVersion>(_DocumentSetVersion);

/**
* Describes a collection of document set versions
*
*/
@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:boolean = 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> {}
export const DocumentSetVersions = graphInvokableFactory<IDocumentSetVersions>(_DocumentSetVersions);

/**
* IListAddResult
*/
export interface IDocumentSetVersionAddResult {
item: IDocumentSetVersion;
data: IDocumentSetVersionEntity;
}

0 comments on commit fcb2fac

Please sign in to comment.