review bug
This commit is contained in:
@@ -24,8 +24,8 @@ export class OrdersController {
|
||||
@ApiBearerAuth()
|
||||
@Get('public/orders')
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAll(@RestId() restId: string, @Query() dto: FindOrdersDto) {
|
||||
return this.ordersService.findAll(restId, dto);
|
||||
findAll(@RestId() restId: string, @Query() dto: FindOrdersDto, @UserId() userId: string) {
|
||||
return this.ordersService.findAllForUser(restId, dto, userId);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@@ -51,7 +51,7 @@ export class OrdersController {
|
||||
@Get('admin/orders')
|
||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||
findAllAdmin(@RestId() restId: string, @Query() dto: FindOrdersDto) {
|
||||
return this.ordersService.findAll(restId, dto);
|
||||
return this.ordersService.findAllForAdmin(restId, dto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Cron, CronExpression } from '@nestjs/schedule';
|
||||
import { OrderRepository } from './repositories/order.repository';
|
||||
import { FindOrdersDto } from './dto/find-orders.dto';
|
||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class OrdersService {
|
||||
private readonly logger = new Logger(OrdersService.name);
|
||||
@@ -247,7 +247,24 @@ export class OrdersService {
|
||||
};
|
||||
}
|
||||
|
||||
async findAll(restId: string, dto: FindOrdersDto): Promise<PaginatedResult<Order>> {
|
||||
async findAllForUser(restId: string, dto: FindOrdersDto, userId: string): Promise<PaginatedResult<Order>> {
|
||||
const result = await this.orderRepository.findAllPaginated(restId, {
|
||||
page: dto.page,
|
||||
limit: dto.limit,
|
||||
status: dto.status,
|
||||
paymentStatus: dto.paymentStatus,
|
||||
search: dto.search,
|
||||
startDate: dto.startDate,
|
||||
endDate: dto.endDate,
|
||||
orderBy: dto.orderBy,
|
||||
order: dto.order,
|
||||
userId,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async findAllForAdmin(restId: string, dto: FindOrdersDto): Promise<PaginatedResult<Order>> {
|
||||
const result = await this.orderRepository.findAllPaginated(restId, {
|
||||
page: dto.page,
|
||||
limit: dto.limit,
|
||||
|
||||
@@ -17,6 +17,7 @@ type FindOrdersOpts = {
|
||||
endDate?: string;
|
||||
orderBy?: string;
|
||||
order?: 'asc' | 'desc';
|
||||
userId?: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
@@ -40,6 +41,7 @@ export class OrderRepository extends EntityRepository<Order> {
|
||||
endDate,
|
||||
orderBy = 'createdAt',
|
||||
order = 'desc',
|
||||
userId,
|
||||
} = opts;
|
||||
|
||||
const offset = (page - 1) * limit;
|
||||
@@ -51,6 +53,10 @@ export class OrderRepository extends EntityRepository<Order> {
|
||||
where.status = status;
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
where.user = { id: userId };
|
||||
}
|
||||
|
||||
// Filter by payment status
|
||||
if (paymentStatus) {
|
||||
where.paymentStatus = paymentStatus;
|
||||
|
||||
Reference in New Issue
Block a user