Bổ sung số đt và địa chỉ vào phần đăng ký tài khoản

This commit is contained in:
2026-06-14 16:10:30 +07:00
parent 3a29f98c96
commit c6d0fdd5d1
10 changed files with 60 additions and 20 deletions
+3 -7
View File
@@ -58,23 +58,19 @@ class AuthController {
@Post('signup')
async signup(@Body() body: any) {
const { email, password, name } = body;
const { email, password, name, phone, address } = body;
// 1. Kiểm tra email tồn tại
const existingUser = await this.prisma.user.findUnique({ where: { email } });
if (existingUser) throw new BadRequestException('Email đã được sử dụng');
// 2. Logic "First User is Admin"
const userCount = await this.prisma.user.count();
const shouldBeAdmin = userCount === 0;
// 3. Hash mật khẩu
const passwordHash = await bcrypt.hash(password, 10);
return this.prisma.user.create({
// Bỏ createdTours: {} vì đây là quan hệ 1-n, Prisma sẽ tự hiểu là mảng rỗng
data: { email, passwordHash, name, isAdmin: shouldBeAdmin },
select: { id: true, email: true, name: true, isAdmin: true }
data: { email, passwordHash, name, phone, address, isAdmin: shouldBeAdmin },
select: { id: true, email: true, name: true, phone: true, address: true, isAdmin: true }
});
}
}