diff --git a/internal/modules/inventory/adjustments/services/adjustment.service.go b/internal/modules/inventory/adjustments/services/adjustment.service.go index 72a15e3a..b913af2e 100644 --- a/internal/modules/inventory/adjustments/services/adjustment.service.go +++ b/internal/modules/inventory/adjustments/services/adjustment.service.go @@ -739,24 +739,25 @@ func (s *adjustmentService) AdjustmentHistory(c *fiber.Ctx, query *validation.Qu } offset := (query.Page - 1) * query.Limit - var isProductsExist bool - isWarehousesExist, err := s.WarehouseRepo.IdExists(c.Context(), uint(query.WarehouseID)) - - if err != nil { - return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate warehouse") - } - if query.WarehouseID > 0 && !isWarehousesExist { - return nil, 0, fiber.NewError(fiber.StatusNotFound, "Warehouse not found") + if query.WarehouseID > 0 { + isWarehouseExist, err := s.WarehouseRepo.IdExists(c.Context(), query.WarehouseID) + if err != nil { + return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate warehouse") + } + if !isWarehouseExist { + return nil, 0, fiber.NewError(fiber.StatusNotFound, "Warehouse not found") + } } - isProductsExist, err = s.ProductRepo.IdExists(c.Context(), uint(query.ProductID)) - - if err != nil { - s.Log.Errorf("Failed to check product existence: %+v", err) - return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate product") - } - if query.ProductID > 0 && !isProductsExist { - return nil, 0, fiber.NewError(fiber.StatusNotFound, "Product not found") + if query.ProductID > 0 { + isProductExist, err := s.ProductRepo.IdExists(c.Context(), query.ProductID) + if err != nil { + s.Log.Errorf("Failed to check product existence: %+v", err) + return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate product") + } + if !isProductExist { + return nil, 0, fiber.NewError(fiber.StatusNotFound, "Product not found") + } } scope, scopeErr := m.ResolveLocationScope(c, s.AdjustmentStockRepository.DB())