frontend helpers for sprint routes

This commit is contained in:
Oliver Bryan
2026-01-12 01:08:40 +00:00
parent 3cef3d3827
commit c9bdfde5ba
4 changed files with 75 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
export * as issue from "@/lib/server/issue";
export * as organisation from "@/lib/server/organisation";
export * as project from "@/lib/server/project";
export * as sprint from "@/lib/server/sprint";
export * as timer from "@/lib/server/timer";
export * as user from "@/lib/server/user";

View File

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

View File

@@ -0,0 +1,47 @@
import { getCsrfToken, getServerURL } from "@/lib/utils";
import type { ServerQueryInput } from "..";
export async function create({
projectId,
name,
color,
startDate,
endDate,
onSuccess,
onError,
}: {
projectId: number;
name: string;
color: string;
startDate: Date;
endDate: Date;
} & ServerQueryInput) {
const url = new URL(`${getServerURL()}/sprint/create`);
url.searchParams.set("projectId", `${projectId}`);
url.searchParams.set("name", name.trim());
url.searchParams.set("color", color);
url.searchParams.set("startDate", startDate.toISOString());
url.searchParams.set("endDate", endDate.toISOString());
const csrfToken = getCsrfToken();
const headers: HeadersInit = {};
if (csrfToken) headers["X-CSRF-Token"] = csrfToken;
const res = await fetch(url.toString(), {
headers,
credentials: "include",
});
if (!res.ok) {
const error = await res.text();
onError?.(error || `failed to create sprint (${res.status})`);
} else {
const data = await res.json();
if (!data.id) {
onError?.(`failed to create sprint (${res.status})`);
return;
}
onSuccess?.(data, res);
}
}

View File

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