-
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.
Merge pull request #2882 from bcameron1231/v4-places
V4 - Microsoft Graph Places
- Loading branch information
Showing
4 changed files
with
245 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,77 @@ | ||
# @pnp/graph/places | ||
|
||
This module allows you to work with Exchange resources such as rooms and roomLists. | ||
|
||
## IPlaces, Places, IPlace, Place, IRoom, Room, IRoomList, RoomList, IRoomLists, RoomLists | ||
|
||
[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) | ||
|
||
## Get all rooms in a Tenant | ||
|
||
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 Rooms in room list | ||
|
||
This example shows how to retrieve all rooms in a roomlist | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/places"; | ||
|
||
const graph = graphfi(...); | ||
const roomsByList = await graph.places.roomLists.getById("05fb1ae2-6de6-4fa8-b852-fb0cf671b896").rooms(); | ||
|
||
``` | ||
## 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,29 @@ | ||
import { GraphFI } from "../fi.js"; | ||
import { IPlaces, Places } from "./types.js"; | ||
|
||
export { | ||
Places, | ||
IPlaces, | ||
Place, | ||
IPlace, | ||
Room, | ||
IRoom, | ||
RoomList, | ||
IRoomlist, | ||
RoomLists, | ||
IRoomlists, | ||
} 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,78 @@ | ||
import { defaultPath, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; | ||
import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; | ||
import { Room as IRoomType, RoomList as IRoomListType, Place as IPlaceType } from "@microsoft/microsoft-graph-types"; | ||
|
||
/** | ||
* Place | ||
*/ | ||
@updateable() | ||
export class _Place extends _GraphInstance<IPlaceType> { } | ||
export interface IPlace extends _Place, IUpdateable<IUpdatePlaceProps> { } | ||
export const Place = graphInvokableFactory<IPlace>(_Place); | ||
|
||
/** | ||
* Places | ||
*/ | ||
@defaultPath("places") | ||
@getById(Place) | ||
export class _Places extends _GraphInstance<IPlace> { | ||
|
||
/** | ||
* Gets all rooms in a tenant | ||
*/ | ||
public get rooms(): IRooms { | ||
return Rooms(this); | ||
} | ||
|
||
/** | ||
* Gets all roomLists in a tenant | ||
*/ | ||
public get roomLists(): IRoomlists { | ||
return RoomLists(this); | ||
} | ||
} | ||
export interface IPlaces extends _Places, IGetById<IPlace> { } | ||
export const Places = graphInvokableFactory<IPlaces>(_Places); | ||
|
||
/** | ||
* RoomList | ||
*/ | ||
export class _RoomList extends _GraphInstance<IRoomListType> { | ||
/** | ||
* Gets all rooms in a roomList | ||
*/ | ||
public get rooms(): IRooms { | ||
return Rooms(this, "rooms"); | ||
} | ||
} | ||
export interface IRoomlist extends _RoomList {} | ||
export const RoomList = graphInvokableFactory<IRoomlist>(_RoomList); | ||
|
||
/** | ||
* RoomLists | ||
*/ | ||
@defaultPath("microsoft.graph.roomList") | ||
@getById(RoomList) | ||
export class _RoomLists extends _GraphCollection<IRoomListType[]> {} | ||
export interface IRoomlists extends _RoomLists, IGetById<IRoomlist> { } | ||
export const RoomLists = graphInvokableFactory<IRoomlists>(_RoomLists); | ||
|
||
/** | ||
* Room | ||
*/ | ||
export class _Room extends _GraphInstance<IRoomType> {} | ||
export interface IRoom extends _Room { } | ||
export const Room = graphInvokableFactory<IRoom>(_Room); | ||
|
||
/** | ||
* Rooms | ||
*/ | ||
@defaultPath("microsoft.graph.room") | ||
@getById(Room) | ||
export class _Rooms extends _GraphCollection<IRoomType[]> {} | ||
export interface IRooms extends _Rooms, IGetById<IRoom> { } | ||
export const Rooms = graphInvokableFactory<IRooms>(_Rooms); | ||
|
||
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,61 @@ | ||
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 room in roomlist", pnpTest("25f24e27-420f-4641-b69d-962597528fdd", async function () { | ||
const roomLists = await this.pnp.graph.places.roomLists(); | ||
if(roomLists.length > 0){ | ||
const rooms = await this.pnp.graph.places.roomLists.getById(roomLists[0].id).rooms(); | ||
return expect(rooms).to.be.an("array"); | ||
} | ||
this.skip(); | ||
})); | ||
|
||
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(); | ||
})); | ||
}); |