This commit is contained in:
2025-09-17 13:12:32 +05:30
parent 08c612287a
commit 6311bd267a
3 changed files with 19 additions and 9 deletions

View File

@@ -83,15 +83,15 @@ export class AuthService {
const expiresAt = new Date();
expiresAt.setMinutes(expiresAt.getMinutes() + 5);
const otp = this.otpService.generateOtp(phone, user??undefined)
const otp = await this.otpService.generateOtp(phone, user??undefined)
// Send SMS using the SMS service
const smsSent = await this.smsService.sendOtp(phone, otpCode);
const smsSent = await this.smsService.sendOtp(phone, otp);
if (!smsSent) {
// If SMS fails, still log to console as fallback for development
console.log(`SMS failed, OTP for ${phone}: ${otpCode}`);
console.log(`SMS failed, OTP for ${phone}: ${otp}`);
return { message: 'OTP generated but SMS delivery may have failed' };
}

View File

@@ -39,6 +39,7 @@ export class UserController {
@Post('register-customer')
@Public()
async createUserWithCustomer(@Body() dto: CreateUserAndCustomerDto) {
console.log(dto)
await this.userService.createUserWithCustomer(dto);
return { message: 'User & customer created successfully' };
}

View File

@@ -75,6 +75,8 @@ export class UserService {
}
async createUserWithCustomer(dto: CreateUserAndCustomerDto): Promise<void> {
console.log('creating 1');
if (
await this.userRepo.findOne({ where: { phone_number: dto.phone_number } })
)
@@ -85,8 +87,9 @@ export class UserService {
// if (!(await this.imageService.exists(dto.proof))) {
// throw new BadRequestException('Proof image does not exist');
// }
console.log('creating');
try {
let savedUser: User | undefined;
await this.userRepo.manager.transaction(async (manager) => {
// Create user
const hashed = await this.hashPassword(dto.password);
@@ -99,7 +102,7 @@ export class UserService {
role: Role.USER,
isActive: true,
});
const savedUser = await manager.save(User, user);
savedUser = await manager.save(User, user);
let proof;
if (dto.proof) {
proof = await this.imageService.confirmImage(dto.proof);
@@ -118,13 +121,19 @@ export class UserService {
proof: proof ?? undefined,
});
await manager.save(Customer, customer);
});
// Generate OTP after transaction completes
if (savedUser) {
console.log(savedUser);
const otp = await this.otpService.generateOtp(
user.phone_number,
user,
savedUser.phone_number,
savedUser,
'LOGIN',
);
await this.smsService.sendOtp(user.phone_number, otp);
});
console.log(otp)
await this.smsService.sendOtp(savedUser.phone_number, otp);
}
} catch (exception) {
throw new BadRequestException(exception);
}