refactor: massive codebase stabilization, strict TS, UI/UX overhaul, and central logging
This commit is contained in:
@@ -1,19 +1,33 @@
|
||||
import { Controller, Post, Body } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Body,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
} from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { Public } from './public.decorator';
|
||||
|
||||
interface LoginDto {
|
||||
login: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private authService: AuthService) {}
|
||||
|
||||
@Public()
|
||||
@Post('login')
|
||||
async login(@Body() req) {
|
||||
async login(@Body() req: LoginDto) {
|
||||
const user = await this.authService.validateUser(req.login, req.password);
|
||||
if (!user) {
|
||||
throw new Error('Invalid credentials');
|
||||
throw new HttpException(
|
||||
'Неверный логин или пароль',
|
||||
HttpStatus.UNAUTHORIZED,
|
||||
);
|
||||
}
|
||||
return this.authService.login(user);
|
||||
return this.authService.login(user as { login: string });
|
||||
}
|
||||
|
||||
@Post('change-password')
|
||||
@@ -27,4 +41,4 @@ export class AuthController {
|
||||
await this.authService.updateAdminProfile(body.login, body.password);
|
||||
return { success: true };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user