2025-01-18 00:46:13 +08:00
|
|
|
import { BASE_URL } from '@/api/buster-rest/instances';
|
|
|
|
import { BusterUserResponse } from './interfaces';
|
|
|
|
import { mainApi } from '../instances';
|
|
|
|
import { serverFetch } from '../../createServerInstance';
|
|
|
|
import { OrganizationUser } from '../organizations';
|
|
|
|
|
2025-01-21 10:42:55 +08:00
|
|
|
export const getMyUserInfo = async ({
|
2025-01-18 00:46:13 +08:00
|
|
|
jwtToken
|
|
|
|
}: {
|
|
|
|
jwtToken: string | undefined;
|
|
|
|
}): Promise<BusterUserResponse | undefined> => {
|
|
|
|
if (!jwtToken) {
|
|
|
|
const res = await serverFetch<BusterUserResponse>(`/users`, {
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
//use fetch instead of serverFetch because...
|
|
|
|
return fetch(`${BASE_URL}/users`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: `Bearer ${jwtToken}`
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getUser = async ({ userId }: { userId: string }) => {
|
|
|
|
return mainApi.get<OrganizationUser>(`/users/${userId}`).then((response) => response.data);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getUser_server = async ({ userId }: { userId: string }) => {
|
|
|
|
return serverFetch<BusterUserResponse>(`/users/${userId}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateOrganizationUser = async ({
|
|
|
|
userId,
|
|
|
|
...params
|
|
|
|
}: {
|
|
|
|
userId: string;
|
|
|
|
name?: string;
|
|
|
|
role: OrganizationUser['role'];
|
|
|
|
}) => {
|
|
|
|
return mainApi
|
|
|
|
.put<OrganizationUser>(`/users/${userId}`, params)
|
|
|
|
.then((response) => response.data);
|
|
|
|
};
|