small refactoring

This commit is contained in:
StarAppeal
2024-11-21 09:54:02 +01:00
parent 155e927a85
commit b510106de3
3 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -3,19 +3,19 @@ import express from "express";
import User from "../db/models/user";
export class RestUser {
constructor(private callback: () => Promise<UserService>) {}
constructor(private createService: () => Promise<UserService>) {}
public createRouter() {
const router = express.Router();
router.get("/", async (req, res) => {
const userService = await this.callback();
const userService = await this.createService();
const users = await userService.getAllUsers();
res.status(200).send({ users });
});
router.get("/:id", async (req, res) => {
const userService = await this.callback();
const userService = await this.createService();
const id = req.params.id;
const user = await userService.getUserById(id);
@@ -27,7 +27,7 @@ export class RestUser {
});
router.put("/:id", async (req, res) => {
const userService = await this.callback();
const userService = await this.createService();
const id = req.params.id;
const user = req.body as User;
const result = await userService.updateUser(id, user);
+2 -2
View File
@@ -1,4 +1,4 @@
import express, { Application, Request, Response, Router } from "express";
import express, { Request, Response, Router } from "express";
import { ExtendedWebSocketServer } from "../websocket";
import { DecodedToken } from "../interfaces/decodedToken";
@@ -15,7 +15,7 @@ export class RestWebSocket {
this.webSocketServer.broadcast(payload);
res.status(200).send("Broadcast erfolgreich.");
res.status(200).send("OK");
});
router.post("/send-message", (req, res) => {
+1 -1
View File
@@ -21,7 +21,7 @@ export class ExtendedWebSocketServer {
private setupWebSocket() {
const serverEventHandler = new WebsocketServerEventHandler(this.wss);
serverEventHandler.enableConnectionEvent((ws) => {
let socketEventHandler = new WebsocketEventHandler(ws);
const socketEventHandler = new WebsocketEventHandler(ws);
console.log("WebSocket client connected");