mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 10:33:01 +00:00
edit + delete capabilities for org, project, sprint
This commit is contained in:
37
packages/frontend/src/lib/server/organisation/delete.ts
Normal file
37
packages/frontend/src/lib/server/organisation/delete.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { SuccessResponse } from "@sprint/shared";
|
||||
import { toast } from "sonner";
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function remove({
|
||||
organisationId,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
organisationId: number;
|
||||
} & ServerQueryInput<SuccessResponse>) {
|
||||
const csrfToken = getCsrfToken();
|
||||
|
||||
const res = await fetch(`${getServerURL()}/organisation/delete`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(csrfToken ? { "X-CSRF-Token": csrfToken } : {}),
|
||||
},
|
||||
body: JSON.stringify({ id: organisationId }),
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json().catch(() => res.text());
|
||||
const message =
|
||||
typeof error === "string"
|
||||
? error
|
||||
: error.error || `failed to delete organisation (${res.status})`;
|
||||
toast.error(message);
|
||||
onError?.(error);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
export { addMember } from "@/lib/server/organisation/addMember";
|
||||
export { byUser } from "@/lib/server/organisation/byUser";
|
||||
export { create } from "@/lib/server/organisation/create";
|
||||
export { remove } from "@/lib/server/organisation/delete";
|
||||
export { members } from "@/lib/server/organisation/members";
|
||||
export { removeMember } from "@/lib/server/organisation/removeMember";
|
||||
export { update } from "@/lib/server/organisation/update";
|
||||
|
||||
35
packages/frontend/src/lib/server/project/delete.ts
Normal file
35
packages/frontend/src/lib/server/project/delete.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { SuccessResponse } from "@sprint/shared";
|
||||
import { toast } from "sonner";
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function remove({
|
||||
projectId,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
projectId: number;
|
||||
} & ServerQueryInput<SuccessResponse>) {
|
||||
const csrfToken = getCsrfToken();
|
||||
|
||||
const res = await fetch(`${getServerURL()}/project/delete`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(csrfToken ? { "X-CSRF-Token": csrfToken } : {}),
|
||||
},
|
||||
body: JSON.stringify({ id: projectId }),
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json().catch(() => res.text());
|
||||
const message =
|
||||
typeof error === "string" ? error : error.error || `failed to delete project (${res.status})`;
|
||||
toast.error(message);
|
||||
onError?.(error);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
export { byOrganisation } from "@/lib/server/project/byOrganisation";
|
||||
export { create } from "@/lib/server/project/create";
|
||||
export { remove } from "@/lib/server/project/delete";
|
||||
export { update } from "@/lib/server/project/update";
|
||||
|
||||
43
packages/frontend/src/lib/server/project/update.ts
Normal file
43
packages/frontend/src/lib/server/project/update.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import type { ProjectRecord } from "@sprint/shared";
|
||||
import { toast } from "sonner";
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function update({
|
||||
projectId,
|
||||
key,
|
||||
name,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
projectId: number;
|
||||
key?: string;
|
||||
name?: string;
|
||||
} & ServerQueryInput<ProjectRecord>) {
|
||||
const csrfToken = getCsrfToken();
|
||||
|
||||
const res = await fetch(`${getServerURL()}/project/update`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(csrfToken ? { "X-CSRF-Token": csrfToken } : {}),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: projectId,
|
||||
key,
|
||||
name,
|
||||
}),
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json().catch(() => res.text());
|
||||
const message =
|
||||
typeof error === "string" ? error : error.error || `failed to update project (${res.status})`;
|
||||
toast.error(message);
|
||||
onError?.(error);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
35
packages/frontend/src/lib/server/sprint/delete.ts
Normal file
35
packages/frontend/src/lib/server/sprint/delete.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { SuccessResponse } from "@sprint/shared";
|
||||
import { toast } from "sonner";
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function remove({
|
||||
sprintId,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
sprintId: number;
|
||||
} & ServerQueryInput<SuccessResponse>) {
|
||||
const csrfToken = getCsrfToken();
|
||||
|
||||
const res = await fetch(`${getServerURL()}/sprint/delete`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(csrfToken ? { "X-CSRF-Token": csrfToken } : {}),
|
||||
},
|
||||
body: JSON.stringify({ id: sprintId }),
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json().catch(() => res.text());
|
||||
const message =
|
||||
typeof error === "string" ? error : error.error || `failed to delete sprint (${res.status})`;
|
||||
toast.error(message);
|
||||
onError?.(error);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
export { byProject } from "@/lib/server/sprint/byProject";
|
||||
export { create } from "@/lib/server/sprint/create";
|
||||
export { remove } from "@/lib/server/sprint/delete";
|
||||
export { update } from "@/lib/server/sprint/update";
|
||||
|
||||
49
packages/frontend/src/lib/server/sprint/update.ts
Normal file
49
packages/frontend/src/lib/server/sprint/update.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { SprintRecord } from "@sprint/shared";
|
||||
import { toast } from "sonner";
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function update({
|
||||
sprintId,
|
||||
name,
|
||||
color,
|
||||
startDate,
|
||||
endDate,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
sprintId: number;
|
||||
name?: string;
|
||||
color?: string;
|
||||
startDate?: Date;
|
||||
endDate?: Date;
|
||||
} & ServerQueryInput<SprintRecord>) {
|
||||
const csrfToken = getCsrfToken();
|
||||
|
||||
const res = await fetch(`${getServerURL()}/sprint/update`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(csrfToken ? { "X-CSRF-Token": csrfToken } : {}),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: sprintId,
|
||||
name: name?.trim(),
|
||||
color,
|
||||
startDate: startDate?.toISOString(),
|
||||
endDate: endDate?.toISOString(),
|
||||
}),
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json().catch(() => res.text());
|
||||
const message =
|
||||
typeof error === "string" ? error : error.error || `failed to update sprint (${res.status})`;
|
||||
toast.error(message);
|
||||
onError?.(error);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user