Skip to content

Commit

Permalink
Make fetch an argument to project api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Apr 24, 2024
1 parent 79d3685 commit 17ba062
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ export async function list(
export async function getOwned(
userId: number,
query?: string,
fetch = globalThis.fetch,
): Promise<Project[]> {
const endpoint = new URL("projects/", BASE_API_URL);
endpoint.searchParams.set("user", String(userId));
endpoint.searchParams.set("query", query);
const projects = await getAll<Project>(endpoint);
const projects = await getAll<Project>(endpoint, undefined, fetch);
return projects.filter((project) => project.user === userId);
}

Expand All @@ -84,11 +85,12 @@ export async function getOwned(
export async function getShared(
userId: number,
query?: string,
fetch = globalThis.fetch,
): Promise<Project[]> {
const endpoint = new URL("projects/", BASE_API_URL);
endpoint.searchParams.set("user", String(userId));
endpoint.searchParams.set("query", query);
const projects = await getAll<Project>(endpoint);
const projects = await getAll<Project>(endpoint, undefined, fetch);
return projects.filter((project) => project.user !== userId);
}

Expand All @@ -101,6 +103,7 @@ export async function pinProject(
csrftoken: string,
id: number,
pinned = true,
fetch = globalThis.fetch,
): Promise<Project> {
const endpoint = new URL(`/api/projects/${id}/`, BASE_API_URL);
const options: RequestInit = {
Expand Down

0 comments on commit 17ba062

Please sign in to comment.