From 70127402febbddd8cdd604fd3d67c0781b2a001b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Vihri=C3=A4l=C3=A4?= <oskar.vihriala@gmail.com> Date: Sun, 5 May 2024 05:24:35 +0300 Subject: [PATCH] Fix name not being read from db on client connect --- backend/src/communication/Client.ts | 11 +++++++++++ backend/src/communication/ConnectionHandler.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/backend/src/communication/Client.ts b/backend/src/communication/Client.ts index f23f4b7..98738d8 100644 --- a/backend/src/communication/Client.ts +++ b/backend/src/communication/Client.ts @@ -44,6 +44,17 @@ export default class Client extends EventEmitter<ClientEvents> { this.fetchInitInfo().catch((err) => { console.error(err); }); + prismaClient.computer + .findUnique({ where: { id: this.id } }) + .then((computer) => { + if (computer) { + this.name = computer.name; + this.emit('nameChanged', this.name); + } + }) + .catch((err) => { + console.error(err); + }); } private forwardNetworkingEvents(): void { diff --git a/backend/src/communication/ConnectionHandler.ts b/backend/src/communication/ConnectionHandler.ts index 194ff9d..09e6687 100644 --- a/backend/src/communication/ConnectionHandler.ts +++ b/backend/src/communication/ConnectionHandler.ts @@ -246,6 +246,7 @@ export default class ConnectionHandler extends EventEmitter<NetworkPacket> { }); }; + // TODO: database transaction if (uuidValidate(clientId)) { this.clientId = clientId; prismaClient.computer -- GitLab