-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# @pnp/graph/places | ||
|
||
This module allows you to work with Exchange resources such as rooms and roomLists. | ||
|
||
## IPlaces, Places, IPlace, Place | ||
|
||
[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) | ||
|
||
## Get all rooms in a Ttenant | ||
|
||
This example shows how to retrieve all rooms in a tenant | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/places"; | ||
|
||
const graph = graphfi(...); | ||
const rooms = graph.places.rooms(); | ||
``` | ||
## Get all roomlists in a tenant | ||
|
||
This example shows how to retrieve all roomlists in a tenant | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/places"; | ||
|
||
const graph = graphfi(...); | ||
const roomLists = graph.places.roomlists(); | ||
|
||
``` | ||
## Get Place by Id | ||
|
||
This example shows how to retrieve a place (room, roomlist) by id | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/places"; | ||
|
||
const graph = graphfi(...); | ||
|
||
const roomById = await graph.places.getById("05fb1ae2-6de6-4fa8-b852-fb0cf671b896")(); | ||
|
||
``` | ||
## Update a place | ||
|
||
This example shows how to update a place (room, roomlist) | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/places"; | ||
|
||
const graph = graphfi(...); | ||
|
||
var updatedRoom = await graph.places.getById("05fb1ae2-6de6-4fa8-b852-fb0cf671b896").update( | ||
{ | ||
'@odata.type': "microsoft.graph.room", | ||
"nickname": "Conf Room", | ||
"building": "1", | ||
"label": "100", | ||
"capacity": 50, | ||
"isWheelChairAccessible": false, | ||
}); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GraphFI } from "../fi.js"; | ||
import { IPlaces, Places } from "./types.js"; | ||
|
||
export { | ||
Places, | ||
IPlaces, | ||
Place, | ||
IPlace, | ||
} from "./types.js"; | ||
|
||
declare module "../fi" { | ||
interface GraphFI { | ||
readonly places: IPlaces; | ||
} | ||
} | ||
|
||
Reflect.defineProperty(GraphFI.prototype, "places", { | ||
configurable: true, | ||
enumerable: true, | ||
get: function (this: GraphFI) { | ||
return this.create(Places); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { defaultPath, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; | ||
import { GraphCollection, _GraphInstance, _GraphQueryable, graphInvokableFactory } from "../graphqueryable.js"; | ||
import { Room as IRoomType, RoomList as IRoomListType } from "@microsoft/microsoft-graph-types"; | ||
|
||
/** | ||
* Place | ||
*/ | ||
@updateable() | ||
export class _Place extends _GraphInstance<IRoomType | IRoomListType> { } | ||
export interface IPlace extends _Place, IUpdateable<IUpdatePlaceProps> { } | ||
export const Place = graphInvokableFactory<IPlace>(_Place); | ||
|
||
/** | ||
* Places | ||
*/ | ||
@defaultPath("places") | ||
@getById(Place) | ||
export class _Places extends _GraphInstance<IPhotosType> { | ||
|
||
/** | ||
* Gets all rooms in a tenant | ||
*/ | ||
public get rooms(): _GraphQueryable<IRoomType[]> { | ||
return GraphCollection(this, "microsoft.graph.room"); | ||
} | ||
|
||
/** | ||
* Gets all roomLists in a tenant | ||
*/ | ||
public get roomLists(): _GraphQueryable<IRoomListType[]> { | ||
return GraphCollection(this, "microsoft.graph.roomList"); | ||
} | ||
} | ||
export interface IPlaces extends _Places, IGetById<IPlace> { } | ||
export const Places = graphInvokableFactory<IPlaces>(_Places); | ||
|
||
export interface IPhotosType { | ||
readonly rooms: IRoomType[]; | ||
readonly roomLists: IRoomListType[]; | ||
} | ||
|
||
export interface IUpdatePlaceProps extends IRoomType, IRoomListType { | ||
"@odata.type": string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { expect } from "chai"; | ||
import { pnpTest } from "../pnp-test.js"; | ||
import "@pnp/graph/places"; | ||
import { getRandomString } from "@pnp/core"; | ||
|
||
describe("Places", function () { | ||
|
||
before(async function () { | ||
|
||
if (!this.pnp.settings.enableWebTests) { | ||
this.skip(); | ||
} | ||
}); | ||
|
||
it("get rooms", pnpTest("7b9a74f6-22f3-4859-bae2-ddb3cba99324", async function () { | ||
const rooms = await this.pnp.graph.places.rooms(); | ||
return expect(rooms).to.be.an("array"); | ||
})); | ||
|
||
it("get roomlists", pnpTest("25f24e27-420f-4641-b69d-962597528fdd", async function () { | ||
const roomLists = await this.pnp.graph.places.roomLists(); | ||
return expect(roomLists).to.be.an("array"); | ||
})); | ||
|
||
it("get place - getById()", pnpTest("b4307200-c208-4246-a571-4ebe06c54f70", async function () { | ||
const rooms = await this.pnp.graph.places.rooms(); | ||
if(rooms.length > 0){ | ||
const room = await this.pnp.graph.places.getById(rooms[0].id)(); | ||
return expect(room).to.haveOwnProperty("id"); | ||
} | ||
this.skip(); | ||
})); | ||
|
||
it.skip("update place", pnpTest("7c3f4418-f1b7-46bf-8944-ee7c7cf896ff", async function () { | ||
const rooms = await this.pnp.graph.places.rooms(); | ||
const randomName = `Conf Room_${getRandomString(4)}`; | ||
if(rooms.length > 0){ | ||
const room = await this.pnp.graph.places.getById(rooms[0].id)(); | ||
const update = await this.pnp.graph.places.getById(room.id).update( | ||
{ | ||
"@odata.type": "microsoft.graph.room", | ||
"nickname": randomName, | ||
"building": "1", | ||
"label": "100", | ||
"capacity": 50, | ||
"isWheelChairAccessible": false, | ||
}); | ||
return expect(update.nickname).to.be(randomName); | ||
} | ||
this.skip(); | ||
})); | ||
}); |