Skip to content

Commit

Permalink
Rename getAll api util
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Apr 12, 2024
1 parent a42dabd commit 37c0501
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/api/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Maybe, User, Org } from "@/api/types";
import { BASE_API_URL, SQUARELET_BASE } from "@/config/config.js";
import { fetchAll } from "../utils/api";
import { getAll } from "../utils/api";
import { alphabetizeUsers } from "../utils/accounts";

type Fetch = typeof globalThis.fetch;
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function getOrgUsers(fetch: Fetch, orgId: number, myId?: number) {
endpoint.searchParams.set("expand", "organization");
endpoint.searchParams.set("organizations", String(orgId));
try {
const users = await fetchAll<User>(fetch, endpoint);
const users = await getAll<User>(fetch, endpoint);
// Sort by admin status, then username
const adminUsers = users
.filter((u) => u.admin_organizations?.includes(orgId))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MAX_PER_PAGE } from "@/config/config";
* Requests the specified URL and paginates through to return all
* results if additional pages are present.
*/
export async function fetchAll<T>(
export async function getAll<T>(
fetch: typeof globalThis.fetch,
url: URL,
perPage: number = MAX_PER_PAGE,
Expand All @@ -16,7 +16,7 @@ export async function fetchAll<T>(
const results = data.results;
if (data.next) {
// Recursively fetch the next page
const nextResults = await fetchAll<T>(fetch, new URL(data.next), perPage);
const nextResults = await getAll<T>(fetch, new URL(data.next), perPage);
return results.concat(nextResults);
}
return results;
Expand Down

0 comments on commit 37c0501

Please sign in to comment.