Sửa lỗi load danh sách người dùng trong quản lí

This commit is contained in:
2026-06-13 18:35:15 +07:00
parent 7b42058d77
commit 7fc80a49d0
7 changed files with 50 additions and 15 deletions
+15 -4
View File
@@ -4,6 +4,9 @@ import { PrismaService } from './prisma.service.js';
import 'dotenv/config';
import * as bcrypt from 'bcrypt';
import { AdminGuard } from './admin.guard.js';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { JwtAuthGuard } from './jwt-auth.guard.js';
import { JwtStrategy } from './jwt.strategy.js';
@Controller()
class AppController {
@@ -15,7 +18,7 @@ class AppController {
@Controller('v1/auth')
class AuthController {
constructor(private prisma: PrismaService) {}
constructor(private prisma: PrismaService, private jwtService: JwtService) {}
@Get('status')
async getStatus() {
@@ -38,8 +41,10 @@ class AuthController {
throw new UnauthorizedException('Tài khoản của bạn đã bị khóa. Vui lòng liên hệ quản trị viên.');
}
const payload = { email: user.email, sub: user.id };
return {
access_token: 'simulated-jwt-token',
access_token: this.jwtService.sign(payload),
user: {
id: user.id,
email: user.email,
@@ -115,7 +120,7 @@ class TourController {
}
@Controller('v1/users')
@UseGuards(AdminGuard)
@UseGuards(JwtAuthGuard, AdminGuard)
class UserController {
constructor(private prisma: PrismaService) {}
@@ -164,8 +169,14 @@ class UserController {
}
@Module({
imports: [
JwtModule.register({
secret: process.env.JWT_SECRET || 'super-secret',
signOptions: { expiresIn: '1d' },
}),
],
controllers: [AppController, AuthController, TourController, UserController],
providers: [PrismaService],
providers: [PrismaService, JwtStrategy],
exports: [PrismaService]
})
class AppModule {}