implement payment cron job

This commit is contained in:
2024-11-25 18:21:54 +07:00
parent 667dc9e09d
commit c063f1a10e

View File

@@ -11,7 +11,7 @@ export class CronService {
// cron every 1 minute to check schedule date status // cron every 1 minute to check schedule date status
@Cron(CronExpression.EVERY_MINUTE) @Cron(CronExpression.EVERY_MINUTE)
async checkScheduleDateStatus() { async checkScheduleDateStatus() {
Logger.log('Checking schedule date status') Logger.log('Checking schedule date status', 'checkScheduleDateStatus')
const schedules = await this.prisma.scheduleDate.findMany({ const schedules = await this.prisma.scheduleDate.findMany({
where: { where: {
end: { end: {
@@ -72,7 +72,7 @@ export class CronService {
// cron every 1 minute to check payment status where created_at is more than 15 minutes // cron every 1 minute to check payment status where created_at is more than 15 minutes
@Cron(CronExpression.EVERY_MINUTE) @Cron(CronExpression.EVERY_MINUTE)
async checkPaymentStatus() { async checkPaymentStatus() {
Logger.log('Checking payment status') Logger.log('Checking payment status', 'checkPaymentStatus')
const payments = await this.prisma.payment.findMany({ const payments = await this.prisma.payment.findMany({
where: { where: {
status: PaymentStatus.PENDING, status: PaymentStatus.PENDING,
@@ -85,5 +85,11 @@ export class CronService {
`Found ${payments.length} payments to update`, `Found ${payments.length} payments to update`,
'checkPaymentStatus', 'checkPaymentStatus',
) )
for (const payment of payments) {
await this.prisma.payment.update({
where: { id: payment.id },
data: { status: PaymentStatus.CANCELLED },
})
}
} }
} }