front-hub/src/api/user.ts

30 lines
807 B
TypeScript
Raw Normal View History

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