diff --git a/docs/graph/places.md b/docs/graph/places.md new file mode 100644 index 000000000..c95e9aa29 --- /dev/null +++ b/docs/graph/places.md @@ -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, + }); + +``` diff --git a/packages/graph/places/index.ts b/packages/graph/places/index.ts new file mode 100644 index 000000000..2bd10ef77 --- /dev/null +++ b/packages/graph/places/index.ts @@ -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); + }, +}); diff --git a/packages/graph/places/types.ts b/packages/graph/places/types.ts new file mode 100644 index 000000000..e9695a553 --- /dev/null +++ b/packages/graph/places/types.ts @@ -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 { } +export interface IPlace extends _Place, IUpdateable { } +export const Place = graphInvokableFactory(_Place); + +/** + * Places + */ +@defaultPath("places") +@getById(Place) +export class _Places extends _GraphInstance { + + /** + * 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 { } +export const Places = graphInvokableFactory(_Places); + +/** + * RoomList + */ +export class _RoomList extends _GraphInstance { + /** + * Gets all rooms in a roomList + */ + public get rooms(): IRooms { + return Rooms(this, "rooms"); + } +} +export interface IRoomlist extends _RoomList {} +export const RoomList = graphInvokableFactory(_RoomList); + +/** + * RoomLists + */ +@defaultPath("microsoft.graph.roomList") +@getById(RoomList) +export class _RoomLists extends _GraphCollection {} +export interface IRoomlists extends _RoomLists, IGetById { } +export const RoomLists = graphInvokableFactory(_RoomLists); + +/** + * Room + */ +export class _Room extends _GraphInstance {} +export interface IRoom extends _Room { } +export const Room = graphInvokableFactory(_Room); + +/** + * Rooms + */ +@defaultPath("microsoft.graph.room") +@getById(Room) +export class _Rooms extends _GraphCollection {} +export interface IRooms extends _Rooms, IGetById { } +export const Rooms = graphInvokableFactory(_Rooms); + +export interface IUpdatePlaceProps extends IRoomType, IRoomListType { + "@odata.type": string; +} diff --git a/test/graph/places.ts b/test/graph/places.ts new file mode 100644 index 000000000..2812c3f0e --- /dev/null +++ b/test/graph/places.ts @@ -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(); + })); +});