Files
sub2api/frontend/src/api/user.ts
ianshaw f79b0f0fad style(frontend): 统一 API 模块代码风格
- 移除所有语句末尾分号
- 统一对象属性尾随逗号格式
- 优化类型定义导入顺序
- 提升代码一致性和可读性
2025-12-26 00:10:44 -08:00

56 lines
1.2 KiB
TypeScript

/**
* User API endpoints
* Handles user profile management and password changes
*/
import { apiClient } from './client'
import type { User, ChangePasswordRequest } from '@/types'
/**
* Get current user profile
* @returns User profile data
*/
export async function getProfile(): Promise<User> {
const { data } = await apiClient.get<User>('/user/profile')
return data
}
/**
* Update current user profile
* @param profile - Profile data to update
* @returns Updated user profile data
*/
export async function updateProfile(profile: {
username?: string
wechat?: string
}): Promise<User> {
const { data } = await apiClient.put<User>('/user', profile)
return data
}
/**
* Change current user password
* @param passwords - Old and new password
* @returns Success message
*/
export async function changePassword(
oldPassword: string,
newPassword: string
): Promise<{ message: string }> {
const payload: ChangePasswordRequest = {
old_password: oldPassword,
new_password: newPassword
}
const { data } = await apiClient.put<{ message: string }>('/user/password', payload)
return data
}
export const userAPI = {
getProfile,
updateProfile,
changePassword
}
export default userAPI