frontend server utility improvement

This commit is contained in:
Oliver Bryan
2025-12-31 17:57:55 +00:00
parent c7d261048b
commit 70ef02f790
19 changed files with 381 additions and 182 deletions

View File

@@ -0,0 +1,26 @@
import { getAuthHeaders, getServerURL } from "@/lib/utils";
import type { ServerQueryInput } from "..";
export async function byProject({
projectId,
onSuccess,
onError,
}: {
projectId: number;
} & ServerQueryInput) {
const url = new URL(`${getServerURL()}/issues/by-project`);
url.searchParams.set("projectId", `${projectId}`);
const res = await fetch(url.toString(), {
headers: getAuthHeaders(),
});
if (!res.ok) {
const error = await res.text();
onError?.(error || `failed to get issues by project (${res.status})`);
} else {
const data = await res.json();
onSuccess?.(data, res);
}
}

View File

@@ -0,0 +1,36 @@
import { getAuthHeaders, getServerURL } from "@/lib/utils";
import type { ServerQueryInput } from "..";
export async function create({
projectId,
title,
description,
onSuccess,
onError,
}: {
projectId: number;
title: string;
description: string;
} & ServerQueryInput) {
const url = new URL(`${getServerURL()}/issue/create`);
url.searchParams.set("projectId", `${projectId}`);
url.searchParams.set("title", title.trim());
if (description.trim() !== "") url.searchParams.set("description", description.trim());
const res = await fetch(url.toString(), {
headers: getAuthHeaders(),
});
if (!res.ok) {
const error = await res.text();
onError?.(error || `failed to create issue (${res.status})`);
} else {
const data = await res.json();
if (!data.id) {
onError?.(`failed to create issue (${res.status})`);
return;
}
onSuccess?.(data, res);
}
}

View File

@@ -0,0 +1,2 @@
export { byProject } from "./byProject";
export { create } from "./create";