feat: Editing, creating and deleting server accounts, user.controller improvements

This commit is contained in:
Aleksi Lassila
2024-06-16 22:15:47 +03:00
parent 9b5be9e2ae
commit 0107b4f7c3
28 changed files with 601 additions and 332 deletions

View File

@@ -1,7 +1,7 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { UserService } from '../user/user.service';
import { UsersService } from '../users/users.service';
import { JwtService } from '@nestjs/jwt';
import { User } from '../user/user.entity';
import { User } from '../users/user.entity';
export interface AccessTokenPayload {
sub: string;
@@ -10,7 +10,7 @@ export interface AccessTokenPayload {
@Injectable()
export class AuthService {
constructor(
private userService: UserService,
private userService: UsersService,
private jwtService: JwtService,
) {}
@@ -23,7 +23,11 @@ export class AuthService {
}> {
let user = await this.userService.findOneByName(name);
if (!user && (await this.userService.noPreviousAdmins()))
user = await this.userService.create(name, password, true);
user = await this.userService.create({
name,
password,
isAdmin: true,
});
if (!(user && user.password === password)) {
throw new UnauthorizedException();