From bb6534de71e4a14b06950f03fa3220c2776961ae Mon Sep 17 00:00:00 2001 From: Tye Peck Date: Tue, 23 Jan 2024 14:53:28 +0800 Subject: [PATCH 1/6] feat: add calendar getSchedule functionality --- packages/graph/calendars/types.ts | 40 ++++++++++++++++++++++++++++++- test/graph/calendars.ts | 22 +++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index 009a969f9..282b30e45 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -1,5 +1,11 @@ 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 IScheduleInformation, + DateTimeTimeZone as IDateTimeTimeZone, + NullableOption, +} 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"; @@ -13,6 +19,9 @@ export class _Calendar extends _GraphQueryableInstance { public get events(): IEvents { return Events(this); } + public get schedule(): ISchedule { + return Schedule(this); + } public calendarView = calendarView; } @@ -71,3 +80,32 @@ export interface IEventAddResult { data: IEventType; event: IEvent; } + + +/** + * Schedule + */ +@defaultPath("getSchedule") +export class _Schedule extends _GraphQueryableCollection { + /** + * 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 get(properties: IGetScheduleRequest): Promise { + + const data = await graphPost(this, body(properties)); + + return data; + } +} +export interface ISchedule extends _Schedule { } +export const Schedule = graphInvokableFactory(_Schedule); + +export interface IGetScheduleRequest { + schedules: string[]; + startTime: IDateTimeTimeZone; + endTime: IDateTimeTimeZone; + availabilityViewInterval?: NullableOption; +} diff --git a/test/graph/calendars.ts b/test/graph/calendars.ts index 68251730b..aea080a0d 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.schedule.get( + { + "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); From ac84f8bf2dced62f9d0f2c19cfadca82fc314670 Mon Sep 17 00:00:00 2001 From: Tye Peck Date: Tue, 23 Jan 2024 14:59:51 +0800 Subject: [PATCH 2/6] docs: add documentation for calendar.getSchedules --- docs/graph/calendars.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 From 58375a7b7f47f94db3c7c22e0fdf5f03ba17c8fc Mon Sep 17 00:00:00 2001 From: Tye Peck Date: Tue, 23 Jan 2024 15:00:17 +0800 Subject: [PATCH 3/6] chore: add type descriptors for calendar get schedule request --- packages/graph/calendars/types.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index 282b30e45..a06e32161 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -104,8 +104,21 @@ export interface ISchedule extends _Schedule { } export const Schedule = graphInvokableFactory(_Schedule); 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: IDateTimeTimeZone; + /** + * The date, time, and time zone that the period ends. + */ endTime: IDateTimeTimeZone; + /** + * 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?: NullableOption; } From 0565a84a4733cce5091bcceab7aa0491d4f4582b Mon Sep 17 00:00:00 2001 From: Tye Peck Date: Thu, 25 Jan 2024 17:57:10 +0800 Subject: [PATCH 4/6] chore: apply code review fixes --- packages/graph/calendars/types.ts | 44 +++++++++++-------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index a06e32161..0a2a48e78 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -2,8 +2,8 @@ import { body } from "@pnp/queryable"; import { Event as IEventType, Calendar as ICalendarType, - ScheduleInformation as IScheduleInformation, - DateTimeTimeZone as IDateTimeTimeZone, + ScheduleInformation as IScheduleInformationType, + DateTimeTimeZone as IDateTimeTimeZoneType, NullableOption, } from "@microsoft/microsoft-graph-types"; import { _GraphQueryableCollection, _GraphQueryableInstance, graphInvokableFactory } from "../graphqueryable.js"; @@ -16,14 +16,22 @@ import { calendarView, instances } from "./funcs.js"; */ export class _Calendar extends _GraphQueryableInstance { + public calendarView = calendarView; + public get events(): IEvents { return Events(this); } - public get schedule(): ISchedule { - return Schedule(this); + + /** + * 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)); } - public calendarView = calendarView; } export interface ICalendar extends _Calendar { } export const Calendar = graphInvokableFactory(_Calendar); @@ -81,28 +89,6 @@ export interface IEventAddResult { event: IEvent; } - -/** - * Schedule - */ -@defaultPath("getSchedule") -export class _Schedule extends _GraphQueryableCollection { - /** - * 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 get(properties: IGetScheduleRequest): Promise { - - const data = await graphPost(this, body(properties)); - - return data; - } -} -export interface ISchedule extends _Schedule { } -export const Schedule = graphInvokableFactory(_Schedule); - export interface IGetScheduleRequest { /** * A collection of SMTP addresses of users, distribution lists, or resources to get availability information for. @@ -111,11 +97,11 @@ export interface IGetScheduleRequest { /** * The date, time, and time zone that the period starts. */ - startTime: IDateTimeTimeZone; + startTime: IDateTimeTimeZoneType; /** * The date, time, and time zone that the period ends. */ - endTime: IDateTimeTimeZone; + 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. From 737d51f9fcc22c16621733529d8134b5b6a09bfb Mon Sep 17 00:00:00 2001 From: Tye Peck Date: Thu, 25 Jan 2024 17:59:45 +0800 Subject: [PATCH 5/6] fix: tests --- test/graph/calendars.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/graph/calendars.ts b/test/graph/calendars.ts index aea080a0d..992f76e28 100644 --- a/test/graph/calendars.ts +++ b/test/graph/calendars.ts @@ -84,7 +84,7 @@ describe("Calendar", function () { startDate.setDate(startDate.getDate() + 1); const endDate: Date = startDate; endDate.setHours(startDate.getHours() + 10); - const schedule = await this.pnp.graph.users.getById(testUserName).calendar.schedule.get( + const schedule = await this.pnp.graph.users.getById(testUserName).calendar.getSchedule( { "schedules": [ testUserName, From 2c650140bcac653abf48d67b9433945d0a9ab536 Mon Sep 17 00:00:00 2001 From: Beau Cameron Date: Thu, 25 Jan 2024 12:40:10 -0700 Subject: [PATCH 6/6] Update to request object availabilityViewInterval request value should be a number --- packages/graph/calendars/types.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index 0a2a48e78..a1c4c6744 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -4,7 +4,6 @@ import { Calendar as ICalendarType, ScheduleInformation as IScheduleInformationType, DateTimeTimeZone as IDateTimeTimeZoneType, - NullableOption, } from "@microsoft/microsoft-graph-types"; import { _GraphQueryableCollection, _GraphQueryableInstance, graphInvokableFactory } from "../graphqueryable.js"; import { defaultPath, IDeleteable, deleteable, IUpdateable, updateable, getById, IGetById } from "../decorators.js"; @@ -106,5 +105,5 @@ export interface IGetScheduleRequest { * 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?: NullableOption; + availabilityViewInterval?: number; }