front-hub/src/api/user.ts

28 lines
797 B
TypeScript
Raw Normal View History

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