summaryrefslogtreecommitdiff
path: root/src/lib/api/ChangeDescription.tsx
diff options
context:
space:
mode:
authorl3wdfut4pwr <l3wdfut4pwr@gmail.com>2026-04-27 14:18:18 +0300
committerl3wdfut4pwr <l3wdfut4pwr@gmail.com>2026-04-27 14:18:18 +0300
commit50cbca3c307894c9fd55baec522b7b794d9ab805 (patch)
treee676102be11e48433e8b1ff79d87fe7d019c845c /src/lib/api/ChangeDescription.tsx
parentab330c64eeed9edfc2a6ef6a6f5cd38587ba0996 (diff)
add description change
Diffstat (limited to 'src/lib/api/ChangeDescription.tsx')
-rw-r--r--src/lib/api/ChangeDescription.tsx45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/lib/api/ChangeDescription.tsx b/src/lib/api/ChangeDescription.tsx
new file mode 100644
index 0000000..e0b760a
--- /dev/null
+++ b/src/lib/api/ChangeDescription.tsx
@@ -0,0 +1,45 @@
+const API_URL = process.env.NEXT_PUBLIC_API_URL;
+
+export const changeDescription = async (description: string) => {
+ try {
+ const res = await fetch(`${API_URL}/api/users/description`, {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ description }),
+ credentials: 'include',
+ });
+
+ if (!res.ok) {
+ let errorData: any = null;
+
+ try {
+ errorData = await res.json();
+ } catch {}
+
+ const detail = errorData?.detail;
+
+ return {
+ data: null,
+ error: {
+ general: Array.isArray(detail)
+ ? detail[0]?.msg
+ : detail?.msg || 'Ошибка изменения описания',
+ },
+ };
+ }
+
+ const data = await res.json();
+
+ return {
+ data,
+ error: null,
+ };
+ } catch (err: any) {
+ return {
+ data: null,
+ error: { general: err.message },
+ };
+ }
+};