Successfully implemented deletion
This commit is contained in:
parent
27194ef68c
commit
a3a4a65a80
1 changed files with 17 additions and 7 deletions
|
@ -6,7 +6,7 @@ const googleAuth = () => {
|
||||||
return new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
|
return new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleErrors(response) {
|
function handleErrorsJson(response) {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
response.json().then(console.log);
|
response.json().then(console.log);
|
||||||
throw Error(response.statusText);
|
throw Error(response.statusText);
|
||||||
|
@ -14,6 +14,13 @@ function handleErrors(response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleErrorsRaw(response) {
|
||||||
|
if (!response.ok) {
|
||||||
|
response.text().then(console.log);
|
||||||
|
throw Error(response.statusText);
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
}
|
||||||
|
|
||||||
const o365Auth = (credential) => {
|
const o365Auth = (credential) => {
|
||||||
|
|
||||||
|
@ -30,7 +37,7 @@ const o365Auth = (credential) => {
|
||||||
'client_secret': process.env.MS_GRAPH_CLIENT_SECRET,
|
'client_secret': process.env.MS_GRAPH_CLIENT_SECRET,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(handleErrors)
|
.then(handleErrorsJson)
|
||||||
.then((responseBody) => {
|
.then((responseBody) => {
|
||||||
credential.key.access_token = responseBody.access_token;
|
credential.key.access_token = responseBody.access_token;
|
||||||
credential.key.expiry_date = Math.round((+(new Date()) / 1000) + responseBody.expires_in);
|
credential.key.expiry_date = Math.round((+(new Date()) / 1000) + responseBody.expires_in);
|
||||||
|
@ -129,7 +136,7 @@ const MicrosoftOffice365Calendar = (credential): CalendarApiAdapter => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
})
|
})
|
||||||
.then(handleErrors)
|
.then(handleErrorsJson)
|
||||||
.then(responseBody => {
|
.then(responseBody => {
|
||||||
return responseBody.value[0].scheduleItems.map((evt) => ({
|
return responseBody.value[0].scheduleItems.map((evt) => ({
|
||||||
start: evt.start.dateTime + 'Z',
|
start: evt.start.dateTime + 'Z',
|
||||||
|
@ -147,13 +154,16 @@ const MicrosoftOffice365Calendar = (credential): CalendarApiAdapter => {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(translateEvent(event))
|
body: JSON.stringify(translateEvent(event))
|
||||||
}).then(handleErrors).then((responseBody) => ({
|
}).then(handleErrorsJson).then((responseBody) => ({
|
||||||
...responseBody,
|
...responseBody,
|
||||||
disableConfirmationEmail: true,
|
disableConfirmationEmail: true,
|
||||||
}))),
|
}))),
|
||||||
deleteEvent: (uid: String) => {
|
deleteEvent: (uid: String) => auth.getToken().then(accessToken => fetch('https://graph.microsoft.com/v1.0/me/calendar/events/' + uid, {
|
||||||
//TODO Implement
|
method: 'DELETE',
|
||||||
},
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + accessToken
|
||||||
|
}
|
||||||
|
}).then(handleErrorsRaw)),
|
||||||
updateEvent: (uid: String, event: CalendarEvent) => {
|
updateEvent: (uid: String, event: CalendarEvent) => {
|
||||||
//TODO Implement
|
//TODO Implement
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue