filter orders with inline payment that not paid

This commit is contained in:
2025-12-23 22:35:48 +03:30
parent b409f0b49f
commit e298ccec32
2 changed files with 18 additions and 1 deletions
@@ -201,6 +201,7 @@ export class OrdersService {
endDate: dto.endDate,
orderBy: dto.orderBy,
order: dto.order,
excludeOnlinePendingPayment: true,
});
return result;
@@ -4,7 +4,7 @@ import { FilterQuery } from '@mikro-orm/core';
import { Order } from '../entities/order.entity';
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
import { OrderStatus } from '../interface/order.interface';
import { PaymentStatusEnum } from '../../payments/interface/payment';
import { PaymentMethodEnum, PaymentStatusEnum } from '../../payments/interface/payment';
import { Review } from '../../review/entities/review.entity';
type FindOrdersOpts = {
@@ -18,6 +18,7 @@ type FindOrdersOpts = {
orderBy?: string;
order?: 'asc' | 'desc';
userId?: string;
excludeOnlinePendingPayment?: boolean;
};
@Injectable()
@@ -41,6 +42,7 @@ export class OrderRepository extends EntityRepository<Order> {
orderBy = 'createdAt',
order = 'desc',
userId,
excludeOnlinePendingPayment = false,
} = opts;
const offset = (page - 1) * limit;
@@ -97,6 +99,20 @@ export class OrderRepository extends EntityRepository<Order> {
where.$or = searchConditions;
}
// Filter: Exclude orders with payment method Online and status pending_payment
if (excludeOnlinePendingPayment) {
const existingConditions = where.$and || [];
where.$and = [
...existingConditions,
{
$or: [
{ paymentMethod: { method: { $ne: PaymentMethodEnum.Online } } },
{ status: { $ne: OrderStatus.PENDING_PAYMENT } },
],
},
];
}
// First, fetch orders without reviews
const [data, total] = await this.findAndCount(where, {
limit,