Browse Source

Add db to web

ghorsington 3 years ago
parent
commit
3217d7843b
4 changed files with 18 additions and 6 deletions
  1. 9 1
      .vscode/settings.json
  2. 1 5
      bot/src/rpc.ts
  3. 1 0
      web/package.json
  4. 7 0
      web/src/server.ts

+ 9 - 1
.vscode/settings.json

@@ -5,5 +5,13 @@
     "python.pythonPath": "/usr/bin/python3",
     "python.linting.pylintArgs": [
         "--generate-members"
-    ]
+    ],
+    "files.exclude": {
+        "**/.git": true,
+        "**/.svn": true,
+        "**/.hg": true,
+        "**/CVS": true,
+        "**/.DS_Store": true,
+        "**/node_modules/": true,
+    }
 }

+ 1 - 5
bot/src/rpc.ts

@@ -17,11 +17,7 @@ const handler: ModuleRpcServer.ServiceHandlerFor<typeof NoctBotService> = {
     },
 
     async userInServer({ userId }): Promise<{ exists: boolean }> {
-        const res = await tryDo(client.bot.users.fetch(userId));
-        if (!res.ok) {
-            return { exists: false };
-        }
-        for (const [_, g] of client.bot.guilds.cache.entries()) {
+        for (const g of client.bot.guilds.cache.values()) {
             const res = await tryDo(g.members.fetch(userId));
             if (res.ok) {
                 return { exists: true };

+ 1 - 0
web/package.json

@@ -40,6 +40,7 @@
 		"rpc_ts": "^2.1.0",
 		"sirv": "^1.0.5",
 		"svelte-awesome": "^2.3.0",
+		"typeorm": "^0.2.25",
 		"winston": "^3.3.3",
 		"winston-transport": "^4.4.0"
 	},

+ 7 - 0
web/src/server.ts

@@ -6,6 +6,8 @@ import express, { Express } from "express";
 import session from "cookie-session";
 // @ts-ignore -- doesn't package its own types until 1.0.0-next.6
 import sirv from "sirv";
+import { createConnection, getConnectionOptions } from "typeorm";
+import { DB_ENTITIES } from "@shared/db/entities";
 import { logger } from "./utils/logging";
 
 const PORT = process.env.PORT; // eslint-disable-line prefer-destructuring
@@ -23,6 +25,11 @@ if (!key) {
 }
 
 const createSapperServer = async (): Promise<Express> => {
+    await createConnection({
+        ...await getConnectionOptions(),
+        entities: DB_ENTITIES,
+    });
+
     const app = express();
 
     app.use(