diff --git a/src/Cron/cron.service.ts b/src/Cron/cron.service.ts index 0bd19f1..cf95f35 100644 --- a/src/Cron/cron.service.ts +++ b/src/Cron/cron.service.ts @@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common' import { Cron } from '@nestjs/schedule' import { CronExpression } from '@nestjs/schedule' import { OrderStatus, PaymentStatus, ScheduleDateStatus, ScheduleStatus } from '@prisma/client' +import { DateTimeUtils } from 'src/common/utils/datetime.utils' import { PrismaService } from 'src/Prisma/prisma.service' @Injectable() @@ -15,7 +16,7 @@ export class CronService { const schedules = await this.prisma.scheduleDate.findMany({ where: { end: { - lt: new Date(), + lt: DateTimeUtils.now().toJSDate(), }, status: { notIn: [ScheduleDateStatus.COMPLETED, ScheduleDateStatus.MISSING_MENTOR, ScheduleDateStatus.MISSING_CUSTOMER], @@ -77,7 +78,7 @@ export class CronService { where: { status: PaymentStatus.PENDING, 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) async 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 const orders = await this.prisma.order.findMany({ where: {