filter orders with inline payment that not paid
This commit is contained in:
@@ -201,6 +201,7 @@ export class OrdersService {
|
|||||||
endDate: dto.endDate,
|
endDate: dto.endDate,
|
||||||
orderBy: dto.orderBy,
|
orderBy: dto.orderBy,
|
||||||
order: dto.order,
|
order: dto.order,
|
||||||
|
excludeOnlinePendingPayment: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { FilterQuery } from '@mikro-orm/core';
|
|||||||
import { Order } from '../entities/order.entity';
|
import { Order } from '../entities/order.entity';
|
||||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
import { OrderStatus } from '../interface/order.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';
|
import { Review } from '../../review/entities/review.entity';
|
||||||
|
|
||||||
type FindOrdersOpts = {
|
type FindOrdersOpts = {
|
||||||
@@ -18,6 +18,7 @@ type FindOrdersOpts = {
|
|||||||
orderBy?: string;
|
orderBy?: string;
|
||||||
order?: 'asc' | 'desc';
|
order?: 'asc' | 'desc';
|
||||||
userId?: string;
|
userId?: string;
|
||||||
|
excludeOnlinePendingPayment?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -41,6 +42,7 @@ export class OrderRepository extends EntityRepository<Order> {
|
|||||||
orderBy = 'createdAt',
|
orderBy = 'createdAt',
|
||||||
order = 'desc',
|
order = 'desc',
|
||||||
userId,
|
userId,
|
||||||
|
excludeOnlinePendingPayment = false,
|
||||||
} = opts;
|
} = opts;
|
||||||
|
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
@@ -97,6 +99,20 @@ export class OrderRepository extends EntityRepository<Order> {
|
|||||||
where.$or = searchConditions;
|
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
|
// First, fetch orders without reviews
|
||||||
const [data, total] = await this.findAndCount(where, {
|
const [data, total] = await this.findAndCount(where, {
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
Reference in New Issue
Block a user