-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sync calendar URL from Moodle to InNoHassle
- Loading branch information
1 parent
b490da7
commit 7d3e2bc
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { events } from '@/shared/innohassle-api/events' | ||
import { moodle } from '@/shared/moodle-ws-api' | ||
import { getStored } from '@/shared/storage' | ||
|
||
export async function syncMoodleCalendarUrl() { | ||
console.log('Syncing Moodle calendar URL...') | ||
|
||
const userId = await getStored('userId') | ||
if (!userId) { | ||
console.log('Warning: No user ID found') | ||
return false | ||
} | ||
|
||
const user = await events.usersGetMe() | ||
if (!user) { | ||
console.log('Warning: No InNoHassle user found') | ||
return false | ||
} | ||
|
||
if (user.moodle_userid === userId) { | ||
console.log('Moodle userid is already connected with InNoHassle') | ||
return false | ||
} | ||
|
||
try { | ||
const { token } = await moodle.core.calendar.getCalendarExportToken({}) | ||
if (!token) { | ||
console.log('Error: No Moodle calendar token found') | ||
return false | ||
} | ||
|
||
await events.usersSetUserMoodleData({ | ||
moodle_userid: userId, | ||
moodle_calendar_authtoken: token, | ||
}) | ||
|
||
console.log('Moodle calendar URL have been synced successfully') | ||
} | ||
catch (e) { | ||
console.log('Error: Couldn\'t get Moodle calendar token') | ||
} | ||
} |