diff --git a/docs/graph/calendars.md b/docs/graph/calendars.md index b25ce0dbc..51f22940f 100644 --- a/docs/graph/calendars.md +++ b/docs/graph/calendars.md @@ -177,6 +177,33 @@ await graph.users.getById('user@tenant.onmicrosoft.com').events.getById(EVENT_ID await graph.me.events.getById(EVENT_ID).delete(); ``` +## Get Schedules + +Get the free/busy availability information for a collection of users, distributions lists, or resources (rooms or equipment) for a specified time period. + +```TypeScript +import { graphfi } from "@pnp/graph"; +import '@pnp/graph/calendars'; +import '@pnp/graph/users'; + +const graph = graphfi(...); + +await graph.users.getById('user@tenant.onmicrosoft.com').calendar.schedule.get( +{ + "startTime": { + "dateTime": "2017-04-15T12:00:00", + "timeZone": "Pacific Standard Time" + }, + "endTime": { + "dateTime": "2017-04-15T14:00:00", + "timeZone": "Pacific Standard Time" + }, + "schedules": [ + "user@tenant.onmicrosoft.com" + ], + "availabilityViewInterval": 30 +}); +``` ## Get Calendar for a Group diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index 009a969f9..a1c4c6744 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -1,5 +1,10 @@ import { body } from "@pnp/queryable"; -import { Event as IEventType, Calendar as ICalendarType } from "@microsoft/microsoft-graph-types"; +import { + Event as IEventType, + Calendar as ICalendarType, + ScheduleInformation as IScheduleInformationType, + DateTimeTimeZone as IDateTimeTimeZoneType, +} from "@microsoft/microsoft-graph-types"; import { _GraphQueryableCollection, _GraphQueryableInstance, graphInvokableFactory } from "../graphqueryable.js"; import { defaultPath, IDeleteable, deleteable, IUpdateable, updateable, getById, IGetById } from "../decorators.js"; import { graphPost } from "../operations.js"; @@ -10,11 +15,22 @@ import { calendarView, instances } from "./funcs.js"; */ export class _Calendar extends _GraphQueryableInstance { + public calendarView = calendarView; + public get events(): IEvents { return Events(this); } - public calendarView = calendarView; + /** + * Get the free/busy availability information for a collection of users, + * distributions lists, or resources (rooms or equipment) for a specified time period. + * + * @param properties The set of properties used to get the schedule + */ + public async getSchedule(properties: IGetScheduleRequest): Promise { + return graphPost(Calendar(this, "getSchedule"), body(properties)); + } + } export interface ICalendar extends _Calendar { } export const Calendar = graphInvokableFactory(_Calendar); @@ -71,3 +87,23 @@ export interface IEventAddResult { data: IEventType; event: IEvent; } + +export interface IGetScheduleRequest { + /** + * A collection of SMTP addresses of users, distribution lists, or resources to get availability information for. + */ + schedules: string[]; + /** + * The date, time, and time zone that the period starts. + */ + startTime: IDateTimeTimeZoneType; + /** + * The date, time, and time zone that the period ends. + */ + endTime: IDateTimeTimeZoneType; + /** + * Represents the duration of a time slot in an availabilityView in the response. + * The default is 30 minutes, minimum is 5, maximum is 1440. Optional. + */ + availabilityViewInterval?: number; +} diff --git a/test/graph/calendars.ts b/test/graph/calendars.ts index 68251730b..992f76e28 100644 --- a/test/graph/calendars.ts +++ b/test/graph/calendars.ts @@ -79,6 +79,28 @@ describe("Calendar", function () { return expect(calendar).is.not.null; }); + it("Get User's Schedule", async function () { + const startDate: Date = new Date(); + startDate.setDate(startDate.getDate() + 1); + const endDate: Date = startDate; + endDate.setHours(startDate.getHours() + 10); + const schedule = await this.pnp.graph.users.getById(testUserName).calendar.getSchedule( + { + "schedules": [ + testUserName, + ], + "startTime": { + "dateTime": startDate.toISOString(), + "timeZone": "Pacific Standard Time", + }, + "endTime": { + "dateTime": endDate.toISOString(), + "timeZone": "Pacific Standard Time", + }, + }); + return expect(schedule).is.not.null; + }); + it("Get Events From User's Default Calendar", async function () { const events = await this.pnp.graph.users.getById(testUserName).calendar.events(); return expect(events.length).is.greaterThan(0);