Sead amin

This commit is contained in:
2026-07-06 13:35:20 +03:30
parent 74d5b7a768
commit bfc077df1c
8 changed files with 190 additions and 0 deletions
+28
View File
@@ -20,6 +20,7 @@ import { SalonSubscriptionsService } from '../subscriptions/salon-subscriptions.
import { UserRole } from '../users/enums/user-role.enum';
import { User } from '../users/entities/user.entity';
import { UsersService } from '../users/users.service';
import { VerifyAdminOtpDto } from './dto/verify-admin-otp.dto';
import { VerifyOtpDto } from './dto/verify-otp.dto';
import { VerifySalonOtpDto } from './dto/verify-salon-otp.dto';
import { Otp } from './entities/otp.entity';
@@ -104,6 +105,13 @@ export class AuthService {
return this.buildOtpRequestResponse(code);
}
async requestAdminOtp(
mobile: string,
): Promise<{ message: string; code?: string }> {
await this.ensureAdminMobile(mobile);
return this.requestOtp(mobile);
}
async checkSalonMobile(
mobile: string,
): Promise<{ isRegistered: boolean }> {
@@ -254,6 +262,14 @@ export class AuthService {
}
}
private async ensureAdminMobile(mobile: string): Promise<void> {
const user = await this.usersService.findByMobile(mobile);
if (!user || user.role !== UserRole.ADMIN) {
throw new BadRequestException('این شماره ادمین نیست');
}
}
private async registerSalonOwner(
dto: VerifySalonOtpDto,
): Promise<SalonAuthResponse> {
@@ -303,6 +319,18 @@ export class AuthService {
return this.issueTokens(user);
}
async verifyAdminOtp(dto: VerifyAdminOtpDto): Promise<AuthTokensResponse> {
await this.ensureAdminMobile(dto.mobile);
await this.consumeOtp(dto.mobile, dto.code);
const user = await this.usersService.findByMobile(dto.mobile);
if (!user || user.role !== UserRole.ADMIN) {
throw new BadRequestException('این شماره ادمین نیست');
}
return this.issueTokens(user);
}
async refresh(refreshToken: string): Promise<AuthTokensResponse> {
const storedTokens = await this.refreshTokenRepository.find({
where: { revokedAt: IsNull() },