otp expire crone
This commit is contained in:
@@ -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 { }
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user