Bổ sung số đt và địa chỉ vào phần đăng ký tài khoản
This commit is contained in:
@@ -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 }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user