implement payment cron job
This commit is contained in:
@@ -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 },
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user