Skip to content

Commit

Permalink
[PBS-84][Anh Dao] fix: get order by staff id
Browse files Browse the repository at this point in the history
  • Loading branch information
toki-ai committed Oct 31, 2024
1 parent 53b4df0 commit e18ce76
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ Page<Order> findOrdersByBuildingNumberAndTimeRange(
@Param("status") OrderStatus status,
Pageable pageable);

@Query("""
SELECT DISTINCT o FROM Order o
JOIN OrderDetail od ON o.id = od.order.id
WHERE od.orderHandler.id = :staffId
AND o.createdAt >= :startTime
AND o.createdAt <= :endTime
AND (:status IS NULL OR od.status = :status)
ORDER BY o.createdAt DESC
""")
Page<Order> findOrdersByStaffIdAndTimeRange(
@Param("staffId") String staffId,
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime,
@Param("status") OrderStatus status,
Pageable pageable);

@Modifying
@Transactional
void deleteById(String id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ public PaginationResponse<List<OrderManagementResponse>> getOrdersByRole(
if (user.getRole().equals(AccountRole.Admin)) {
ordersPage = orderRepository.findAllWithTimeRange(
startDate, endDate, status, PageRequest.of(page, size));
} else if (user.getRole().equals(AccountRole.Staff) || user.getRole().equals(AccountRole.Manager)) {
} else if (user.getRole().equals(AccountRole.Manager)) {
int buildingNumber = user.getBuildingNumber();
ordersPage = orderRepository.findOrdersByBuildingNumberAndTimeRange(
buildingNumber, startDate, endDate, status, PageRequest.of(page, size));
} else {
}else if (user.getRole().equals(AccountRole.Staff)) {
String staffId = user.getId();
ordersPage = orderRepository.findOrdersByStaffIdAndTimeRange(
staffId, startDate, endDate, status, PageRequest.of(page, size));
}
else {
throw new IllegalArgumentException("User role not authorized to access orders.");
}
return convertToPaginationResponse(ordersPage);
Expand Down

0 comments on commit e18ce76

Please sign in to comment.