otp expire crone

This commit is contained in:
2026-01-20 20:36:22 +03:30
parent 6ba36ca130
commit ca8d6c473d
4 changed files with 147 additions and 121 deletions
+2 -1
View File
@@ -14,6 +14,7 @@ import { NotificationsModule } from '../notification/notifications.module';
import { OtpRepository } from './repository/otp.repository';
import { OtpService } from './services/otp.service';
import { Otp } from './entities/otp.entity';
import { AuthCrone } from './crone/auth.crone';
@Module({
imports: [
@@ -40,7 +41,7 @@ import { Otp } from './entities/otp.entity';
],
controllers: [AuthController],
providers: [AuthService, TokensService, AdminAuthGuard, OtpRepository, OtpService],
providers: [AuthService, TokensService, AdminAuthGuard, OtpRepository, OtpService, AuthCrone],
exports: [AdminAuthGuard],
})
export class AuthModule { }
+25
View File
@@ -0,0 +1,25 @@
import { Injectable, Logger } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { OtpRepository } from '../repository/otp.repository';
@Injectable()
export class AuthCrone {
private readonly logger = new Logger(AuthCrone.name);
constructor(
private readonly otpRepository: OtpRepository
) { }
@Cron('*/59 * * * *', {
name: 'completeOldDeliveredOrders',
timeZone: 'UTC',
})
async removeExpireOtp() {
this.logger.log("Delete expire otps")
await this.otpRepository.nativeDelete({
expiresAt: { $lt: new Date() }
})
return true
}
}