small refactoring
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user