aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/GeneralGoogleManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/ApiManagers/GeneralGoogleManager.ts')
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts
index 12913b1ef..aa06ca1b3 100644
--- a/src/server/ApiManagers/GeneralGoogleManager.ts
+++ b/src/server/ApiManagers/GeneralGoogleManager.ts
@@ -3,6 +3,8 @@ import { Method } from '../RouteManager';
import { GoogleApiServerUtils } from '../apis/google/GoogleApiServerUtils';
import RouteSubscriber from '../RouteSubscriber';
import { Database } from '../database';
+import { google } from 'googleapis';
+
const EndpointHandlerMap = new Map<GoogleApiServerUtils.Action, GoogleApiServerUtils.ApiRouter>([
['create', (api, params) => api.create(params)],
@@ -61,5 +63,38 @@ export default class GeneralGoogleManager extends ApiManager {
res.send(undefined);
},
});
+
+ // AARAV ADD (creating a task)
+
+ register({
+ method: Method.POST,
+ subscription: new RouteSubscriber('googleTasks').add('create'),
+ secureHandler: async ({ req, res, user }) => {
+ try {
+ const { credentials } = await GoogleApiServerUtils.retrieveCredentials(user.id);
+ if (!credentials?.access_token) {
+ return res.status(401).send('Google access token not found.');
+ }
+
+ const auth = new google.auth.OAuth2();
+ auth.setCredentials({ access_token: credentials.access_token });
+
+ const tasks = google.tasks({ version: 'v1', auth });
+
+ const { title, notes, due } = req.body;
+ const result = await tasks.tasks.insert({
+ tasklist: '@default',
+ requestBody: { title, notes, due },
+ });
+
+ res.status(200).send(result.data);
+ } catch (err) {
+ console.error('Google Tasks error:', err);
+ res.status(500).send('Failed to create task.');
+ }
+ },
+ });
+
+
}
}