diff --git a/bc_obps/registration/api/v1/transfer_events.py b/bc_obps/registration/api/v1/transfer_events.py index 970084118e..41789e1648 100644 --- a/bc_obps/registration/api/v1/transfer_events.py +++ b/bc_obps/registration/api/v1/transfer_events.py @@ -1,4 +1,5 @@ -from typing import List, Literal, Optional, Dict, Any +from typing import List, Literal, Optional +from registration.models.event.transfer_event import TransferEvent from registration.schema.v1.transfer_event import TransferEventFilterSchema, TransferEventListOut from service.transfer_event_service import TransferEventService from common.permissions import authorize @@ -11,6 +12,7 @@ from service.error_service.custom_codes_4xx import custom_codes_4xx from ninja import Query from registration.schema.generic import Message +from django.db.models import QuerySet @router.get( @@ -29,6 +31,6 @@ def list_transfer_events( sort_field: Optional[str] = "status", sort_order: Optional[Literal["desc", "asc"]] = "desc", paginate_result: bool = Query(True, description="Whether to paginate the results"), -) -> List[Dict[str, Any]]: +) -> QuerySet[TransferEvent]: # NOTE: PageNumberPagination raises an error if we pass the response as a tuple (like 200, ...) return TransferEventService.list_transfer_events(sort_field, sort_order, filters) diff --git a/bc_obps/registration/schema/v1/transfer_event.py b/bc_obps/registration/schema/v1/transfer_event.py index 52ca201fe4..b11801472e 100644 --- a/bc_obps/registration/schema/v1/transfer_event.py +++ b/bc_obps/registration/schema/v1/transfer_event.py @@ -1,7 +1,6 @@ from typing import Optional from uuid import UUID -from registration.models.facility import Facility from registration.models.event.transfer_event import TransferEvent from ninja import ModelSchema, Field, FilterSchema from django.db.models import Q @@ -9,12 +8,6 @@ from typing import Dict, Any -class FacilityForTransferEventGrid(ModelSchema): - class Meta: - model = Facility - fields = ['name'] - - class TransferEventListOut(ModelSchema): operation__id: Optional[UUID] = None operation__name: Optional[str] = Field(None, alias="operation__name") @@ -46,7 +39,8 @@ class TransferEventFilterSchema(FilterSchema): facilities__name: Optional[str] = Field(None, json_schema_extra={'q': 'facilities__name__icontains'}) status: Optional[str] = Field(None, json_schema_extra={'q': 'status__icontains'}) - def filtering_including_not_applicable(self, field: str, value: str) -> Q: + @staticmethod + def filtering_including_not_applicable(field: str, value: str) -> Q: if value and re.search(value, 'n/a', re.IGNORECASE): return Q(**{f"{field}__icontains": value}) | Q(**{f"{field}__isnull": True}) return Q(**{f"{field}__icontains": value}) if value else Q() diff --git a/bc_obps/service/transfer_event_service.py b/bc_obps/service/transfer_event_service.py index 7b5530a5cc..70680dc531 100644 --- a/bc_obps/service/transfer_event_service.py +++ b/bc_obps/service/transfer_event_service.py @@ -1,7 +1,7 @@ +from typing import cast +from django.db.models import QuerySet from registration.models.event.transfer_event import TransferEvent -from typing import Optional, Dict, Any, List - - +from typing import Optional from registration.schema.v1.transfer_event import TransferEventFilterSchema from ninja import Query @@ -13,7 +13,7 @@ def list_transfer_events( sort_field: Optional[str], sort_order: Optional[str], filters: TransferEventFilterSchema = Query(...), - ) -> List[Dict[str, Any]]: + ) -> QuerySet[TransferEvent]: sort_direction = "-" if sort_order == "desc" else "" sort_by = f"{sort_direction}{sort_field}" queryset = ( @@ -29,4 +29,4 @@ def list_transfer_events( ) .distinct() ) - return list(queryset) + return cast(QuerySet[TransferEvent], queryset) diff --git a/bciers/apps/administration/app/components/operations/OperationDataGridPage.tsx b/bciers/apps/administration/app/components/operations/OperationDataGridPage.tsx index 8cbf325c05..c14369a504 100644 --- a/bciers/apps/administration/app/components/operations/OperationDataGridPage.tsx +++ b/bciers/apps/administration/app/components/operations/OperationDataGridPage.tsx @@ -20,9 +20,8 @@ export default async function OperationDataGridPage({ rows: OperationRow[]; row_count: number; } = await fetchOperationsPageData(searchParams); - if (!operations) { - return
No operations data in database.
; - } + if (!operations || "error" in operations) + throw new Error("Failed to retrieve operations"); const isAuthorizedAdminUser = [ FrontEndRoles.CAS_ADMIN, diff --git a/bciers/apps/administration/app/components/operators/OperatorDataGridPage.tsx b/bciers/apps/administration/app/components/operators/OperatorDataGridPage.tsx index 2ec985815c..569047c578 100644 --- a/bciers/apps/administration/app/components/operators/OperatorDataGridPage.tsx +++ b/bciers/apps/administration/app/components/operators/OperatorDataGridPage.tsx @@ -15,9 +15,8 @@ export default async function Operators({ rows: OperatorRow[]; row_count: number; } = await fetchOperatorsPageData(searchParams); - if (!operators) { - return
No operator data in database.
; - } + if (!operators || "error" in operators) + throw new Error("Failed to retrieve operators"); // Render the DataGrid component return ( diff --git a/bciers/apps/administration/tests/components/operations/OperationDataGridPage.test.tsx b/bciers/apps/administration/tests/components/operations/OperationDataGridPage.test.tsx index 5e3dc37e6d..b09bf991c5 100644 --- a/bciers/apps/administration/tests/components/operations/OperationDataGridPage.test.tsx +++ b/bciers/apps/administration/tests/components/operations/OperationDataGridPage.test.tsx @@ -51,11 +51,12 @@ describe("Operations component", () => { vi.clearAllMocks(); }); - it("renders a message when there are no operations in the database", async () => { + it("throws an error when there's a problem fetching data", async () => { fetchOperationsPageData.mockReturnValueOnce(undefined); - render(await Operations({ searchParams: {} })); + await expect(async () => { + render(await Operations({ searchParams: {} })); + }).rejects.toThrow("Failed to retrieve operations"); expect(screen.queryByRole("grid")).not.toBeInTheDocument(); - expect(screen.getByText(/No operations data in database./i)).toBeVisible(); }); it("renders the OperationDataGrid component when there are operations in the database", async () => { diff --git a/bciers/apps/administration/tests/components/operators/OperatorDataGridPage.test.tsx b/bciers/apps/administration/tests/components/operators/OperatorDataGridPage.test.tsx index b9122f83af..e1ce46058d 100644 --- a/bciers/apps/administration/tests/components/operators/OperatorDataGridPage.test.tsx +++ b/bciers/apps/administration/tests/components/operators/OperatorDataGridPage.test.tsx @@ -54,11 +54,13 @@ describe("OperatorDataGridPage component", () => { vi.clearAllMocks(); }); - it("renders a message when there are no operators in the database", async () => { + it("throws an error when there's a problem fetching data", async () => { fetchOperatorsPageData.mockReturnValueOnce(undefined); - render(await Operators({ searchParams: {} })); + await expect(async () => { + render(await Operators({ searchParams: {} })); + }).rejects.toThrow("Failed to retrieve operators"); + expect(screen.queryByRole("grid")).not.toBeInTheDocument(); - expect(screen.getByText(/No operator data in database./i)).toBeVisible(); }); it("renders the OperatorDataGrid component when there are operators in the database", async () => { diff --git a/bciers/apps/registration/app/components/datagrid/models/transfers/transferColumns.ts b/bciers/apps/registration/app/components/datagrid/models/transfers/transferColumns.ts index dc13a5be88..0a36dd3eb4 100644 --- a/bciers/apps/registration/app/components/datagrid/models/transfers/transferColumns.ts +++ b/bciers/apps/registration/app/components/datagrid/models/transfers/transferColumns.ts @@ -7,7 +7,6 @@ const transferColumns = ( { field: "created_at", headerName: "Submission Date", - // Set flex to 1 to make the column take up all the remaining width if user zooms out width: 200, }, { field: "operation__name", headerName: "Operation", width: 200 }, diff --git a/bciers/apps/registration/app/components/transfers/TransfersDataGrid.tsx b/bciers/apps/registration/app/components/transfers/TransfersDataGrid.tsx index 9f529c717d..95879d78cb 100644 --- a/bciers/apps/registration/app/components/transfers/TransfersDataGrid.tsx +++ b/bciers/apps/registration/app/components/transfers/TransfersDataGrid.tsx @@ -25,7 +25,6 @@ const TransfersDataGrid = ({ row_count: number; }; }) => { - console.log("initial", initialData); const [lastFocusedField, setLastFocusedField] = useState(null); const SearchCell = useMemo( diff --git a/bciers/apps/registration/app/components/transfers/TransfersDataGridPage.tsx b/bciers/apps/registration/app/components/transfers/TransfersDataGridPage.tsx index ecc4431fc3..10db935b36 100644 --- a/bciers/apps/registration/app/components/transfers/TransfersDataGridPage.tsx +++ b/bciers/apps/registration/app/components/transfers/TransfersDataGridPage.tsx @@ -15,9 +15,8 @@ export default async function TransfersDataGridPage({ rows: TransferRow[]; row_count: number; } = await fetchTransferEventsPageData(searchParams); - if (!transfers) { - return
No transfers data in database.
; - } + if (!transfers || "error" in transfers) + throw new Error("Failed to retrieve transfers"); // Render the DataGrid component return ( diff --git a/bciers/apps/registration/app/idir/cas_admin/transfers/page.tsx b/bciers/apps/registration/app/idir/cas_analyst/transfers/page.tsx similarity index 100% rename from bciers/apps/registration/app/idir/cas_admin/transfers/page.tsx rename to bciers/apps/registration/app/idir/cas_analyst/transfers/page.tsx diff --git a/bciers/apps/registration/tests/components/transfers/TransfersDataGridPage.test.tsx b/bciers/apps/registration/tests/components/transfers/TransfersDataGridPage.test.tsx index 7e353ef591..997c4e6765 100644 --- a/bciers/apps/registration/tests/components/transfers/TransfersDataGridPage.test.tsx +++ b/bciers/apps/registration/tests/components/transfers/TransfersDataGridPage.test.tsx @@ -73,11 +73,12 @@ describe("Transfers component", () => { vi.clearAllMocks(); }); - it("renders a message when there are no transfers in the database", async () => { + it("throws an error when there's a problem fetching data", async () => { fetchTransferEventsPageData.mockReturnValueOnce(undefined); - render(await TransfersDataGridPage({ searchParams: {} })); + await expect(async () => { + render(await TransfersDataGridPage({ searchParams: {} })); + }).rejects.toThrow("Failed to retrieve transfers"); expect(screen.queryByRole("grid")).not.toBeInTheDocument(); - expect(screen.getByText(/No transfers data in database./i)).toBeVisible(); }); it("renders the TransfersDataGrid component when there are transfers in the database", async () => {