diff options
author | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-03 13:10:05 -0400 |
---|---|---|
committer | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-03 13:10:05 -0400 |
commit | 6e7a29470e2c9e2fad287b4851b9eb561821ea9e (patch) | |
tree | 6c727148bef5bc87af3f5326fcb239bbc3198e6b /src/server/apis/google/GoogleTasksHandler.ts | |
parent | 0b4659e2d85c5311835651d3f1aa54c48f3849de (diff) |
fixed drag and drop of calendar events not following cursor properly
Diffstat (limited to 'src/server/apis/google/GoogleTasksHandler.ts')
-rw-r--r-- | src/server/apis/google/GoogleTasksHandler.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/server/apis/google/GoogleTasksHandler.ts b/src/server/apis/google/GoogleTasksHandler.ts new file mode 100644 index 000000000..a8af86fe2 --- /dev/null +++ b/src/server/apis/google/GoogleTasksHandler.ts @@ -0,0 +1,54 @@ +import express from 'express'; +import { google } from 'googleapis'; +import { GoogleCredentialsLoader } from './CredentialsLoader'; +import User from '../../authentication/DashUserModel'; +import { DashUserModel } from '../../authentication/DashUserModel'; + + +const router = express.Router(); + +router.post('/tasks/create', async (req, res) => { + try { + const { title, notes, due } = req.body; + + // Make sure user is authenticated + if (!req.user) { + return res.status(401).json({ error: 'User not authenticated' }); + } + + // Assuming access token is stored in user model + const user = req.user as typeof User; // replace with your actual User type if needed + const accessToken = user.googleAccessToken; // <-- change this based on where you store it + + if (!accessToken) { + return res.status(400).json({ error: 'Google access token not found for user' }); + } + + const credentials = GoogleCredentialsLoader.ProjectCredentials; + const auth = new google.auth.OAuth2( + credentials.client_id, + credentials.client_secret, + credentials.redirect_uris[0] + ); + + auth.setCredentials({ access_token: accessToken }); + + const tasks = google.tasks({ version: 'v1', auth }); + + const result = await tasks.tasks.insert({ + tasklist: '@default', + requestBody: { + title, + notes, + due, + }, + }); + + res.status(200).json(result.data); + } catch (err) { + console.error('Error creating Google Task:', err); + res.status(500).json({ error: 'Failed to create task' }); + } +}); + +export default router; |