Refactor CronService to utilize DateTimeUtils for date handling. Update schedule and payment checks to use current time instead of new Date(), enhancing accuracy in scheduling logic. This change improves the reliability of cron job operations by ensuring consistent date management.
This commit is contained in:
@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common'
|
|||||||
import { Cron } from '@nestjs/schedule'
|
import { Cron } from '@nestjs/schedule'
|
||||||
import { CronExpression } from '@nestjs/schedule'
|
import { CronExpression } from '@nestjs/schedule'
|
||||||
import { OrderStatus, PaymentStatus, ScheduleDateStatus, ScheduleStatus } from '@prisma/client'
|
import { OrderStatus, PaymentStatus, ScheduleDateStatus, ScheduleStatus } from '@prisma/client'
|
||||||
|
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
|
||||||
import { PrismaService } from 'src/Prisma/prisma.service'
|
import { PrismaService } from 'src/Prisma/prisma.service'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -15,7 +16,7 @@ export class CronService {
|
|||||||
const schedules = await this.prisma.scheduleDate.findMany({
|
const schedules = await this.prisma.scheduleDate.findMany({
|
||||||
where: {
|
where: {
|
||||||
end: {
|
end: {
|
||||||
lt: new Date(),
|
lt: DateTimeUtils.now().toJSDate(),
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
notIn: [ScheduleDateStatus.COMPLETED, ScheduleDateStatus.MISSING_MENTOR, ScheduleDateStatus.MISSING_CUSTOMER],
|
notIn: [ScheduleDateStatus.COMPLETED, ScheduleDateStatus.MISSING_MENTOR, ScheduleDateStatus.MISSING_CUSTOMER],
|
||||||
@@ -77,7 +78,7 @@ export class CronService {
|
|||||||
where: {
|
where: {
|
||||||
status: PaymentStatus.PENDING,
|
status: PaymentStatus.PENDING,
|
||||||
createdAt: {
|
createdAt: {
|
||||||
lt: new Date(Date.now() - 15 * 60 * 1000),
|
lt: DateTimeUtils.now().minus({ minutes: 15 }).toJSDate(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -98,7 +99,7 @@ export class CronService {
|
|||||||
@Cron(CronExpression.EVERY_MINUTE)
|
@Cron(CronExpression.EVERY_MINUTE)
|
||||||
async handleRefundTicket() {
|
async handleRefundTicket() {
|
||||||
Logger.log('Handling refund ticket', 'handleRefundTicket')
|
Logger.log('Handling refund ticket', 'handleRefundTicket')
|
||||||
const now = new Date()
|
const now = DateTimeUtils.now().toJSDate()
|
||||||
// get all orders where status is REFUNDED and has schedule.dates in future
|
// get all orders where status is REFUNDED and has schedule.dates in future
|
||||||
const orders = await this.prisma.order.findMany({
|
const orders = await this.prisma.order.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user