mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
frontend helpers for sprint routes
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
25
packages/frontend/src/lib/server/sprint/byProject.ts
Normal file
25
packages/frontend/src/lib/server/sprint/byProject.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
47
packages/frontend/src/lib/server/sprint/create.ts
Normal file
47
packages/frontend/src/lib/server/sprint/create.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
2
packages/frontend/src/lib/server/sprint/index.ts
Normal file
2
packages/frontend/src/lib/server/sprint/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { byProject } from "@/lib/server/sprint/byProject";
|
||||
export { create } from "@/lib/server/sprint/create";
|
||||
Reference in New Issue
Block a user