fix: the problem in the invoice pay
This commit is contained in:
@@ -3,7 +3,7 @@ import { BadRequestException, Injectable, Logger } from "@nestjs/common";
|
||||
import { Queue } from "bullmq";
|
||||
import dayjs from "dayjs";
|
||||
import Decimal from "decimal.js";
|
||||
import { Between, DataSource, QueryRunner } from "typeorm";
|
||||
import { Between, DataSource, In, QueryRunner } from "typeorm";
|
||||
|
||||
import { AuthMessage, InvoiceMessage, WalletMessage } from "../../../common/enums/message.enum";
|
||||
import { VerifyOtpWithUserId } from "../../auth/DTO/verify-otp.dto";
|
||||
@@ -557,9 +557,10 @@ export class InvoicesService {
|
||||
|
||||
const user = await this.usersService.findOneByIdWithQueryRunner(userId, queryRunner);
|
||||
|
||||
const invoice = await this.getPendingInvoiceByIdWithQueryRunner(invoiceId, user.id, queryRunner);
|
||||
const invoice = await this.getPendingOrOverdueInvoiceByIdWithQueryRunner(invoiceId, user.id, queryRunner);
|
||||
|
||||
if (invoice.status !== InvoiceStatus.WAIT_PAYMENT) throw new BadRequestException(InvoiceMessage.INVOICE_CAN_NOT_PAID);
|
||||
if (invoice.status !== InvoiceStatus.WAIT_PAYMENT && invoice.status !== InvoiceStatus.OVERDUE)
|
||||
throw new BadRequestException(InvoiceMessage.INVOICE_CAN_NOT_PAID);
|
||||
|
||||
const userWallet = await this.walletsService.getWalletByUserId(user.id, queryRunner);
|
||||
|
||||
@@ -632,11 +633,11 @@ export class InvoicesService {
|
||||
|
||||
//*********************************** */
|
||||
|
||||
async getPendingInvoiceByIdWithQueryRunner(invoiceId: string, userId: string, queryRunner: QueryRunner) {
|
||||
async getPendingOrOverdueInvoiceByIdWithQueryRunner(invoiceId: string, userId: string, queryRunner: QueryRunner) {
|
||||
const invoice = await queryRunner.manager.findOne(Invoice, {
|
||||
where: {
|
||||
user: { id: userId },
|
||||
status: InvoiceStatus.WAIT_PAYMENT,
|
||||
status: In([InvoiceStatus.WAIT_PAYMENT, InvoiceStatus.OVERDUE]),
|
||||
id: invoiceId,
|
||||
},
|
||||
relations: {
|
||||
|
||||
Reference in New Issue
Block a user