mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 10:33:01 +00:00
delete issue functionality
This commit is contained in:
30
packages/frontend/src/lib/server/issue/delete.ts
Normal file
30
packages/frontend/src/lib/server/issue/delete.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function remove({
|
||||
issueId,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
issueId: number;
|
||||
} & ServerQueryInput) {
|
||||
const url = new URL(`${getServerURL()}/issue/delete`);
|
||||
url.searchParams.set("id", `${issueId}`);
|
||||
|
||||
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 delete issue (${res.status})`);
|
||||
} else {
|
||||
const data = await res.text();
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export { byProject } from "@/lib/server/issue/byProject";
|
||||
export { create } from "@/lib/server/issue/create";
|
||||
export { remove as delete } from "@/lib/server/issue/delete";
|
||||
export { replaceStatus } from "@/lib/server/issue/replaceStatus";
|
||||
export { statusCount } from "@/lib/server/issue/statusCount";
|
||||
export { update } from "@/lib/server/issue/update";
|
||||
|
||||
Reference in New Issue
Block a user