small refactoring
This commit is contained in:
@@ -13,6 +13,15 @@ export interface IUser extends Document {
|
||||
location: string;
|
||||
}
|
||||
|
||||
export interface CreateUserPayload {
|
||||
name: string,
|
||||
password: string,
|
||||
uuid: string,
|
||||
config: UserConfig,
|
||||
timezone: string;
|
||||
location: string;
|
||||
}
|
||||
|
||||
export interface UserConfig {
|
||||
isVisible: boolean;
|
||||
canBeModified: boolean;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {IUser, SpotifyConfig, UserModel} from "../../models/user";
|
||||
import {CreateUserPayload, IUser, SpotifyConfig, UserModel} from "../../models/user";
|
||||
import {connectToDatabase} from "./database.service";
|
||||
import {Document, UpdateQuery} from "mongoose";
|
||||
import { UpdateQuery} from "mongoose";
|
||||
|
||||
export class UserService {
|
||||
private static _instance: UserService;
|
||||
@@ -52,7 +52,7 @@ export class UserService {
|
||||
return await UserModel.findOne({uuid}, {spotifyConfig: 1}).exec().then(user => user?.spotifyConfig);
|
||||
}
|
||||
|
||||
public async createUser(userData: Omit<IUser, keyof Document>): Promise<IUser> {
|
||||
public async createUser(userData: CreateUserPayload): Promise<IUser> {
|
||||
try {
|
||||
const newUser = await UserModel.create(userData);
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import express from "express";
|
||||
import {UserService} from "../db/services/db/UserService";
|
||||
import {IUser} from "../db/models/user";
|
||||
import {CreateUserPayload, IUser} from "../db/models/user";
|
||||
import {JwtAuthenticator} from "../utils/jwtAuthenticator";
|
||||
import crypto from "crypto";
|
||||
import {PasswordUtils} from "../utils/passwordUtils";
|
||||
@@ -45,7 +45,7 @@ export class RestAuth {
|
||||
}
|
||||
|
||||
const hashedPassword = await PasswordUtils.hashPassword(password);
|
||||
const newUser: Omit<IUser, keyof Document> = {
|
||||
const newUser: CreateUserPayload = {
|
||||
name: username,
|
||||
password: hashedPassword,
|
||||
uuid: crypto.randomUUID(),
|
||||
|
||||
@@ -21,7 +21,8 @@ export class WebsocketServerEventHandler {
|
||||
async (ws: ExtendedWebSocket, request: ExtendedIncomingMessage) => {
|
||||
const user = await this.userService.getUserByUUID(request.payload.uuid);
|
||||
|
||||
ws.user = user!;
|
||||
if (!user) { ws.terminate(); return; }
|
||||
ws.user = user;
|
||||
|
||||
// first: map the payload from the request to the ws object (is payloed needed anymore?)
|
||||
ws.payload = request.payload;
|
||||
|
||||
+2
-2
@@ -79,11 +79,11 @@ export class ExtendedWebSocketServer {
|
||||
ws.emit(WebsocketEventType.UPDATE_USER, {});
|
||||
|
||||
const mode = ws.user.lastState?.global.mode;
|
||||
if (mode === "clock" && !ws.asyncUpdates) {
|
||||
if (mode === "clock") {
|
||||
ws.emit(WebsocketEventType.GET_WEATHER_UPDATES, {})
|
||||
}
|
||||
|
||||
if (mode === "music" && !ws.asyncUpdates) {
|
||||
if (mode === "music") {
|
||||
ws.emit(WebsocketEventType.GET_SPOTIFY_UPDATES, {})
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user