mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
update user backend + frontend server function
This commit is contained in:
1
packages/frontend/src/lib/server/user/index.ts
Normal file
1
packages/frontend/src/lib/server/user/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { update } from "./update";
|
||||
39
packages/frontend/src/lib/server/user/update.ts
Normal file
39
packages/frontend/src/lib/server/user/update.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { getAuthHeaders, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function update({
|
||||
id,
|
||||
name,
|
||||
password,
|
||||
serverURL,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
id: number;
|
||||
name: string;
|
||||
password: string;
|
||||
serverURL: string;
|
||||
} & ServerQueryInput) {
|
||||
const url = new URL(`${getServerURL()}/user/update`);
|
||||
url.searchParams.set("id", `${id}`);
|
||||
url.searchParams.set("name", name.trim());
|
||||
url.searchParams.set("password", password.trim());
|
||||
url.searchParams.set("serverURL", serverURL.trim());
|
||||
|
||||
const res = await fetch(url.toString(), {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.text();
|
||||
onError?.(error || `failed to update user (${res.status})`);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (!data.id) {
|
||||
onError?.(`failed to update user (${res.status})`);
|
||||
return;
|
||||
}
|
||||
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user