gitscope
← marzneshin / v0.3.0-alpha5 / dashboard/src/components/entity-table/tests/fetch-entity.mock.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/components/entity-table/tests/fetch-entity.mock.ts · TypeScript
Blame Raw
 1import { EntityQueryKeyType, FetchEntityReturn } from "..";
 2import { MockApiData, MockDataType } from "./data.mock";
 3
 4export const fetchMockApi = ({ queryKey }: EntityQueryKeyType): FetchEntityReturn<MockDataType> => {
 5    const pageSize = queryKey[1]
 6    const pageIndex = queryKey[2]
 7    const startIndex = pageSize * pageIndex;
 8    const endIndex = startIndex + pageSize;
 9    const paginatedData = MockApiData.slice(startIndex, endIndex);
10    const pages = Math.round(MockApiData.length / pageSize)
11
12    return new Promise((resolve,) => {
13        resolve({ entity: paginatedData, pageCount: pages })
14    })
15}