2023-11-05 23:33:40 +00:00
|
|
|
|
import { User, makeRequest } from "@frontend/kitui"
|
|
|
|
|
import { PatchUserRequest } from "@root/model/user"
|
|
|
|
|
import { parseAxiosError } from "@root/utils/parse-error"
|
2023-05-30 18:34:41 +00:00
|
|
|
|
|
2024-01-17 20:04:39 +00:00
|
|
|
|
const apiUrl = process.env.REACT_APP_DOMAIN + "/user"
|
2023-05-30 18:34:41 +00:00
|
|
|
|
|
2023-08-30 11:49:55 +00:00
|
|
|
|
export async function patchUser(
|
2023-11-05 23:33:40 +00:00
|
|
|
|
user: PatchUserRequest
|
2023-08-30 11:49:55 +00:00
|
|
|
|
): Promise<[User | null, string?]> {
|
2023-11-05 23:33:40 +00:00
|
|
|
|
try {
|
|
|
|
|
const patchUserResponse = await makeRequest<PatchUserRequest, User>({
|
|
|
|
|
url: apiUrl,
|
|
|
|
|
contentType: true,
|
|
|
|
|
method: "PATCH",
|
|
|
|
|
useToken: true,
|
|
|
|
|
withCredentials: false,
|
|
|
|
|
body: user,
|
|
|
|
|
})
|
2023-08-30 11:49:55 +00:00
|
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
|
return [patchUserResponse]
|
|
|
|
|
} catch (nativeError) {
|
|
|
|
|
const [error] = parseAxiosError(nativeError)
|
2023-08-30 11:49:55 +00:00
|
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
|
return [null, `Не удалось изменить пользователя. ${error}`]
|
|
|
|
|
}
|
2023-08-28 14:34:52 +00:00
|
|
|
|
}
|