-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.js
More file actions
188 lines (136 loc) · 4.25 KB
/
graph.js
File metadata and controls
188 lines (136 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Create an authentication provider
const authProvider = {
getAccessToken: async () => {
// Call getToken in auth.js
return await getToken();
}
};
// Initialize the Graph client
const graphClient = MicrosoftGraph.Client.initWithMiddleware({ authProvider });
//Get user info from Graph
async function getUser() {
ensureScope('user.read');
return await graphClient
.api('/me')
.select('id,displayName,mail')
.get();
}
async function getUserPhoto() {
ensureScope('user.read');
return await graphClient
.api('/me/photo/$value')
.get();
}
async function getUsersPhoto(id) {
ensureScope('user.read.all');
return await graphClient
.api(`/users/${id}/photo/\$value`)
.get();
}
async function getTeamPhoto(id) {
ensureScope('user.read.all');
ensureScope('Team.ReadBasic.All');
return await graphClient
.api(`/teams/${id}/photo/\$value`)
.get();
}
async function getTeam() {
ensureScope('Team.ReadBasic.All');
ensureScope('user.read.all');
//ensureScope('user.readwrite.all');
return await graphClient
.api('/me/joinedTeams')
.select('id,displayName')
.get();
}
async function getTeam_member(id) {
ensureScope('Team.ReadBasic.All');
ensureScope('user.read.all');
//ensureScope('Group.ReadWrite.All');
//ensureScope('user.readwrite.all');
return await graphClient
.api(`/groups/${id}/members`)
.select('id,displayName')
.get();
}
async function getEvents() {
ensureScope('Calendars.read');
ensureScope('User.Read.All');
const dateNow = new Date();
const dateNextWeek = new Date();
const endOfDay = new Date();
endOfDay.setUTCHours(28, 59, 59, 999);
dateNextWeek.setDate(dateNextWeek.getDate() + 1);
const query = `startDateTime=${dateNow.toISOString().slice(0,-1)}&endDateTime=${endOfDay.toISOString().slice(0,-1)}`;
//const ptherQuery = `startDateTime=${dateNow.toISOString()}&endDateTime=${dateNextWeek.toISOString()}`;
return await graphClient
.api('/me/calendarView').query(query)
.header('Prefer', 'outlook.timezone="Haiti Standard Time"')
.select('subject,start,end,location,attendees,isOnlineMeeting')
.orderby(`start/DateTime`)
.get();
}
async function getUser_presence(id) {
ensureScope('Presence.Read.All');
//ensureScope('Group.ReadWrite.All');
//ensureScope('user.readwrite.all');
return await graphClient
.api(`/users/${id}/presence`)
.get();
}
// Graph call for To Do tasks
async function getTo_do() {
ensureScope('Tasks.ReadWrite');
//ensureScope('user.readwrite.all');
return await graphClient
.api('/me/todo/lists')
.get();
}
async function getTo_do_tasks(id) {
ensureScope('Tasks.ReadWrite');
//ensureScope('user.readwrite.all');
return await graphClient
.api(`/me/todo/lists/${id}/tasks`)
//.select('id,title')
.get();
}
async function create_task(tasks){
ensureScope('Tasks.ReadWrite');
//ensureScope('user.readwrite.all');
const todoTask = {
title: tasks,
categories: ['Important'],
linkedResources: [
{
webUrl: 'http://microsoft.com',
applicationName: 'Microsoft',
displayName: 'Microsoft'
}
]
};
return await graphClient
.api("/me/todo/lists/AAMkAGI1NmZmYzM1LWI3MmYtNDliYy1hNDQ3LTVhMTMzYmI1N2NiNwAuAAAAAABP5cn6S0koRrsXwUrS_NbOAQAfzBZps-PQTLzOh7s3yXfKAAAAAAESAAA=/tasks")
.post(todoTask);
//.select('id,title')
//.get();
}
async function completed_task(id,id_){
ensureScope('Tasks.ReadWrite');
const task ={
status: "completed"
};
return await graphClient
.api(`/me/todo/lists/${id}/tasks/${id_}`)
//.select('id,title')
.update(task);
}
async function uncompleted_task(id,id_){
ensureScope('Tasks.ReadWrite');
const task ={
status: "notStarted"
};
return await graphClient
.api(`/me/todo/lists/${id}/tasks/${id_}`)
//.select('id,title')
.update(task);
}