front-hub/src/api/user.ts

28 lines
790 B
TypeScript
Raw Normal View History

2023-05-30 18:34:41 +00:00
import { PatchUserRequest, User } from "@root/model/user";
import { authStore } from "@root/stores/makeRequest";
const apiUrl = process.env.NODE_ENV === "production" ? "" : "https://hub.pena.digital";
const makeRequest = authStore.getState().makeRequest;
export function getUser(userId: string): Promise<User | null> {
return makeRequest<never, User>({
url: `${apiUrl}/user/${userId}`,
contentType: true,
method: "GET",
useToken: false,
withCredentials: false,
});
}
export function patchUser(user: PatchUserRequest) {
return makeRequest<PatchUserRequest, User>({
url: apiUrl + "/user/",
contentType: true,
method: "PATCH",
useToken: true,
withCredentials: false,
body: user,
});
}