aboutsummaryrefslogtreecommitdiff
path: root/src/server/index.ts
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-08-21 20:01:35 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-08-21 20:01:35 -0400
commitf4888ec4b2862cdf890ac1b0f6670b41398266df (patch)
tree76e00e66bae3ccbb4cc34e0bb8e2e9510f5c67c7 /src/server/index.ts
parent88454c8163115b1396a34f4836b5f6f04817a3f0 (diff)
can create google slides presentations
Diffstat (limited to 'src/server/index.ts')
-rw-r--r--src/server/index.ts19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/server/index.ts b/src/server/index.ts
index ef1829f30..6aecb875a 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -45,6 +45,7 @@ import { GoogleApiServerUtils } from "./apis/google/GoogleApiServerUtils";
import { GaxiosResponse } from 'gaxios';
import { Opt } from '../new_fields/Doc';
import { docs_v1 } from 'googleapis';
+import { Endpoint } from 'googleapis-common';
const MongoStore = require('connect-mongo')(session);
const mongoose = require('mongoose');
const probe = require("probe-image-size");
@@ -799,21 +800,19 @@ function HandleYoutubeQuery([query, callback]: [YoutubeQueryInput, (result?: any
const credentials = path.join(__dirname, "./credentials/google_docs_credentials.json");
const token = path.join(__dirname, "./credentials/google_docs_token.json");
-type ApiResponse = Promise<GaxiosResponse>;
-type ApiHandler = (endpoint: docs_v1.Resource$Documents, parameters: any) => ApiResponse;
-type Action = "create" | "retrieve" | "update";
-
-const EndpointHandlerMap = new Map<Action, ApiHandler>([
+const EndpointHandlerMap = new Map<GoogleApiServerUtils.Action, GoogleApiServerUtils.ApiRouter>([
["create", (api, params) => api.create(params)],
["retrieve", (api, params) => api.get(params)],
["update", (api, params) => api.batchUpdate(params)],
]);
-app.post(RouteStore.googleDocs + ":action", (req, res) => {
- GoogleApiServerUtils.Docs.GetEndpoint({ credentials, token }).then(endpoint => {
- let handler = EndpointHandlerMap.get(req.params.action);
- if (handler) {
- let execute = handler(endpoint.documents, req.body).then(
+app.post(RouteStore.googleDocs + ":sector/:action", (req, res) => {
+ let sector = req.params.sector;
+ let action = req.params.action;
+ GoogleApiServerUtils.GetEndpoint(GoogleApiServerUtils.Sector[sector], { credentials, token }).then(endpoint => {
+ let handler = EndpointHandlerMap.get(action);
+ if (endpoint && handler) {
+ let execute = handler(endpoint, req.body).then(
response => res.send(response.data),
rejection => res.send(rejection)
);