From e95f74891f01547288716d4c2bcc482e8a94a72b Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 4 Sep 2021 15:10:04 +0300 Subject: [PATCH] Added room list fetching from database and sending of it on user connection --- back/src/db/index.ts | 4 ++++ back/src/index.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/back/src/db/index.ts b/back/src/db/index.ts index 117f73c..a2be23a 100644 --- a/back/src/db/index.ts +++ b/back/src/db/index.ts @@ -17,4 +17,8 @@ export const connect = () => entities: [Room], }); +export const getRoomList = (connection: Connection) => { + return connection.manager.find(Room); +}; + export { Room }; diff --git a/back/src/index.ts b/back/src/index.ts index 0bab5b9..3da887c 100644 --- a/back/src/index.ts +++ b/back/src/index.ts @@ -1,12 +1,15 @@ import "reflect-metadata"; import { Server } from "ws"; +import { connect, getRoomList } from "./db"; (async () => { + const connection = await connect(); + const wss = new Server({ port: Number.parseInt(process.env.PORT || "") || 8081, }); wss.on("connection", async (ws) => { - ws.send("hello"); + ws.send(JSON.stringify(await getRoomList(connection))); }); })();