Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add calendar getSchedule functionality #2914

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/graph/calendars.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,33 @@ await graph.users.getById('[email protected]').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('[email protected]').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": [
"[email protected]"
],
"availabilityViewInterval": 30
});
```

## Get Calendar for a Group

Expand Down
40 changes: 38 additions & 2 deletions packages/graph/calendars/types.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -10,11 +15,22 @@ import { calendarView, instances } from "./funcs.js";
*/
export class _Calendar extends _GraphQueryableInstance<ICalendarType> {

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<IScheduleInformationType[]> {
return graphPost(Calendar(this, "getSchedule"), body(properties));
}

}
export interface ICalendar extends _Calendar { }
export const Calendar = graphInvokableFactory<ICalendar>(_Calendar);
Expand Down Expand Up @@ -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;
}
22 changes: 22 additions & 0 deletions test/graph/calendars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading