review bug
This commit is contained in:
@@ -24,8 +24,8 @@ export class OrdersController {
|
|||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Get('public/orders')
|
@Get('public/orders')
|
||||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||||
findAll(@RestId() restId: string, @Query() dto: FindOrdersDto) {
|
findAll(@RestId() restId: string, @Query() dto: FindOrdersDto, @UserId() userId: string) {
|
||||||
return this.ordersService.findAll(restId, dto);
|
return this.ordersService.findAllForUser(restId, dto, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
@@ -51,7 +51,7 @@ export class OrdersController {
|
|||||||
@Get('admin/orders')
|
@Get('admin/orders')
|
||||||
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
|
||||||
findAllAdmin(@RestId() restId: string, @Query() dto: FindOrdersDto) {
|
findAllAdmin(@RestId() restId: string, @Query() dto: FindOrdersDto) {
|
||||||
return this.ordersService.findAll(restId, dto);
|
return this.ordersService.findAllForAdmin(restId, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
|
|||||||
@@ -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, {
|
const result = await this.orderRepository.findAllPaginated(restId, {
|
||||||
page: dto.page,
|
page: dto.page,
|
||||||
limit: dto.limit,
|
limit: dto.limit,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type FindOrdersOpts = {
|
|||||||
endDate?: string;
|
endDate?: string;
|
||||||
orderBy?: string;
|
orderBy?: string;
|
||||||
order?: 'asc' | 'desc';
|
order?: 'asc' | 'desc';
|
||||||
|
userId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -40,6 +41,7 @@ export class OrderRepository extends EntityRepository<Order> {
|
|||||||
endDate,
|
endDate,
|
||||||
orderBy = 'createdAt',
|
orderBy = 'createdAt',
|
||||||
order = 'desc',
|
order = 'desc',
|
||||||
|
userId,
|
||||||
} = opts;
|
} = opts;
|
||||||
|
|
||||||
const offset = (page - 1) * limit;
|
const offset = (page - 1) * limit;
|
||||||
@@ -51,6 +53,10 @@ export class OrderRepository extends EntityRepository<Order> {
|
|||||||
where.status = status;
|
where.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userId) {
|
||||||
|
where.user = { id: userId };
|
||||||
|
}
|
||||||
|
|
||||||
// Filter by payment status
|
// Filter by payment status
|
||||||
if (paymentStatus) {
|
if (paymentStatus) {
|
||||||
where.paymentStatus = paymentStatus;
|
where.paymentStatus = paymentStatus;
|
||||||
|
|||||||
Reference in New Issue
Block a user