fix(client): 接口结果修正
This commit is contained in:
@@ -54,32 +54,38 @@ export const apiRequest = async <T = any>(
|
|||||||
|
|
||||||
// 便捷的HTTP方法封装
|
// 便捷的HTTP方法封装
|
||||||
export const api = {
|
export const api = {
|
||||||
get: <T = any>(endpoint: string, options?: RequestOptions): Promise<T> =>
|
get: <T = any>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>> =>
|
||||||
apiRequest<T>(endpoint, { ...options, method: 'GET' }),
|
apiRequest<ApiResponse<T>>(endpoint, { ...options, method: 'GET' }),
|
||||||
|
|
||||||
post: <T = any>(endpoint: string, data?: any, options?: RequestOptions): Promise<T> =>
|
post: <T = any>(endpoint: string, data?: any, options?: RequestOptions): Promise<ApiResponse<T>> =>
|
||||||
apiRequest<T>(endpoint, {
|
apiRequest<ApiResponse<T>>(endpoint, {
|
||||||
...options,
|
...options,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: data ? JSON.stringify(data) : undefined,
|
body: data ? JSON.stringify(data) : undefined,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
put: <T = any>(endpoint: string, data?: any, options?: RequestOptions): Promise<T> =>
|
put: <T = any>(endpoint: string, data?: any, options?: RequestOptions): Promise<ApiResponse<T>> =>
|
||||||
apiRequest<T>(endpoint, {
|
apiRequest<ApiResponse<T>>(endpoint, {
|
||||||
...options,
|
...options,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: data ? JSON.stringify(data) : undefined,
|
body: data ? JSON.stringify(data) : undefined,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
patch: <T = any>(endpoint: string, data?: any, options?: RequestOptions): Promise<T> =>
|
patch: <T = any>(endpoint: string, data?: any, options?: RequestOptions): Promise<ApiResponse<T>> =>
|
||||||
apiRequest<T>(endpoint, {
|
apiRequest<ApiResponse<T>>(endpoint, {
|
||||||
...options,
|
...options,
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: data ? JSON.stringify(data) : undefined,
|
body: data ? JSON.stringify(data) : undefined,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
delete: <T = any>(endpoint: string, options?: RequestOptions): Promise<T> =>
|
delete: <T = any>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>> =>
|
||||||
apiRequest<T>(endpoint, { ...options, method: 'DELETE' }),
|
apiRequest<ApiResponse<T>>(endpoint, { ...options, method: 'DELETE' }),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ApiResponse<T> = {
|
||||||
|
code: number;
|
||||||
|
message: string;
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
|
||||||
export default api;
|
export default api;
|
||||||
|
|||||||
@@ -14,13 +14,15 @@ export type UserInfo = {
|
|||||||
/**
|
/**
|
||||||
* 获取当前用户的信息
|
* 获取当前用户的信息
|
||||||
*/
|
*/
|
||||||
export const getUserInfo = async (): Promise<UserInfo> => {
|
export const getUserInfo = async (): Promise<UserInfo | null> => {
|
||||||
return await api.get<UserInfo>('/api/user/info');
|
const res = await api.get<UserInfo>('/api/user/info');
|
||||||
|
return res.code === 200 ? res.data : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取群组内所有用户的信息
|
* 获取群组内所有用户的信息
|
||||||
*/
|
*/
|
||||||
export const getGroupUsers = async (): Promise<UserInfo[]> => {
|
export const getGroupUsers = async (): Promise<UserInfo[]> => {
|
||||||
return await api.get<UserInfo[]>('/api/group/members');
|
const res = await api.get<UserInfo[]>('/api/group/members');
|
||||||
|
return res.code === 200 ? res.data || [] : [];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user