Compare commits

...

1 Commits

Author SHA1 Message Date
Adnan Zahir 34c690956a fix: error checking id exists 2026-03-09 22:48:18 +07:00
@@ -739,25 +739,26 @@ func (s *adjustmentService) AdjustmentHistory(c *fiber.Ctx, query *validation.Qu
} }
offset := (query.Page - 1) * query.Limit offset := (query.Page - 1) * query.Limit
var isProductsExist bool if query.WarehouseID > 0 {
isWarehousesExist, err := s.WarehouseRepo.IdExists(c.Context(), uint(query.WarehouseID)) isWarehouseExist, err := s.WarehouseRepo.IdExists(c.Context(), query.WarehouseID)
if err != nil { if err != nil {
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate warehouse") return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate warehouse")
} }
if query.WarehouseID > 0 && !isWarehousesExist { if !isWarehouseExist {
return nil, 0, fiber.NewError(fiber.StatusNotFound, "Warehouse not found") return nil, 0, fiber.NewError(fiber.StatusNotFound, "Warehouse not found")
} }
}
isProductsExist, err = s.ProductRepo.IdExists(c.Context(), uint(query.ProductID)) if query.ProductID > 0 {
isProductExist, err := s.ProductRepo.IdExists(c.Context(), query.ProductID)
if err != nil { if err != nil {
s.Log.Errorf("Failed to check product existence: %+v", err) s.Log.Errorf("Failed to check product existence: %+v", err)
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate product") return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate product")
} }
if query.ProductID > 0 && !isProductsExist { if !isProductExist {
return nil, 0, fiber.NewError(fiber.StatusNotFound, "Product not found") return nil, 0, fiber.NewError(fiber.StatusNotFound, "Product not found")
} }
}
scope, scopeErr := m.ResolveLocationScope(c, s.AdjustmentStockRepository.DB()) scope, scopeErr := m.ResolveLocationScope(c, s.AdjustmentStockRepository.DB())
if scopeErr != nil { if scopeErr != nil {