This commit is contained in:
2026-03-10 12:21:25 +03:30
parent ef2f4bf796
commit 0c0774bdca
19 changed files with 26 additions and 657 deletions
+7 -18
View File
@@ -1,28 +1,14 @@
import { Injectable, BadRequestException } from '@nestjs/common';
import { RequestOtpDto } from '../dto/request-otp.dto';
import { CacheService } from '../../utils/cache.service';
import { SmsService } from '../../notifications/services/sms.service';
import { randomInt } from 'crypto';
import { Injectable } from '@nestjs/common';
import { TokensService } from './tokens.service';
import { AuthMessage, RestMessage } from 'src/common/enums/message.enum';
import { AdminRepository } from 'src/modules/admin/repositories/admin.repository';
import { ConfigService } from '@nestjs/config';
import { normalizePhone } from '../../utils/phone.util';
import { BusinessService } from 'src/modules/business/business.service';
@Injectable()
export class AuthService {
readonly ADMIN_PERMISSIONS_KEY = 'admin-perms';
private OTP_EXPIRATION_TIME: number;
constructor(
private readonly cacheService: CacheService,
private readonly smsService: SmsService,
private readonly tokensService: TokensService,
private readonly adminRepository: AdminRepository,
private readonly configService: ConfigService,
private readonly businessService: BusinessService,
) {
this.OTP_EXPIRATION_TIME = this.configService.get<number>('OTP_EXPIRATION_TIME') ?? 240;
}
// private userOtpKey(restaurantSlug: string, phone: string) {
@@ -33,8 +19,11 @@ export class AuthService {
// return `otp-admin:${restaurantSlug}:${phone}`;
// }
directLogin(danakSubId: string) {
const business=this.businessService.findBySubIdOrFail(danakSubId)
async directLogin(danakSubId: string) {
const business = await this.businessService.findBySubIdOrFail(danakSubId)
const admin = business.admin
const tokens = await this.tokensService.generateAccessAndRefreshToken(admin.id, business.id);
return tokens
}
// async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {