This commit is contained in:
2026-07-03 13:19:17 +03:30
parent fb4ddb4dac
commit e55d57047d
5 changed files with 101 additions and 4 deletions
+37
View File
@@ -15,6 +15,8 @@ import { Repository, IsNull } from 'typeorm';
import { Customer } from '../customers/entities/customer.entity';
import { Salon } from '../salons/entities/salon.entity';
import { SmsService } from '../sms/sms.service';
import { SalonSubscription } from '../subscriptions/entities/salon-subscription.entity';
import { SalonSubscriptionsService } from '../subscriptions/salon-subscriptions.service';
import { UserRole } from '../users/enums/user-role.enum';
import { User } from '../users/entities/user.entity';
import { UsersService } from '../users/users.service';
@@ -22,6 +24,7 @@ import { VerifyOtpDto } from './dto/verify-otp.dto';
import { VerifySalonOtpDto } from './dto/verify-salon-otp.dto';
import { Otp } from './entities/otp.entity';
import { RefreshToken } from './entities/refresh-token.entity';
import { AuthUser } from './interfaces/auth-user.interface';
import { JwtPayload } from './interfaces/jwt-payload.interface';
export interface AuthTokensResponse {
@@ -40,6 +43,12 @@ export interface SalonAuthResponse extends AuthTokensResponse {
salon?: Salon;
}
export interface MeResponse {
user: AuthTokensResponse['user'];
salons?: Salon[];
activeSubscription?: SalonSubscription | null;
}
@Injectable()
export class AuthService {
private readonly logger = new Logger(AuthService.name);
@@ -60,6 +69,7 @@ export class AuthService {
@InjectRepository(Salon)
private readonly salonsRepository: Repository<Salon>,
private readonly usersService: UsersService,
private readonly salonSubscriptionsService: SalonSubscriptionsService,
private readonly smsService: SmsService,
private readonly jwtService: JwtService,
private readonly configService: ConfigService,
@@ -336,6 +346,33 @@ export class AuthService {
throw new UnauthorizedException('Invalid refresh token');
}
async getMe(authUser: AuthUser): Promise<MeResponse> {
const user = await this.usersService.findOne(authUser.id);
const response: MeResponse = {
user: {
id: user.id,
firstName: user.firstName,
lastName: user.lastName,
mobile: user.mobile,
role: user.role,
},
};
if (user.role === UserRole.SALON) {
response.salons = await this.salonsRepository.find({
where: { ownerId: user.id },
order: { createdAt: 'ASC' },
});
response.activeSubscription =
await this.salonSubscriptionsService.findActiveSubscriptionForOwner(
user.id,
);
}
return response;
}
private async resolveUserForLogin(dto: VerifyOtpDto): Promise<User> {
const existingUser = await this.usersService.findByMobile(dto.mobile);