Update GPT and add Profile
This commit is contained in:
42
frontend/src/api/users.ts
Normal file
42
frontend/src/api/users.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import client from './client'
|
||||
import type { User, UserProfilePublic, UserStats, PasswordChangeData } from '@/types'
|
||||
|
||||
export interface UpdateNicknameData {
|
||||
nickname: string
|
||||
}
|
||||
|
||||
export const usersApi = {
|
||||
// Получить публичный профиль пользователя со статистикой
|
||||
getProfile: async (userId: number): Promise<UserProfilePublic> => {
|
||||
const response = await client.get<UserProfilePublic>(`/users/${userId}/profile`)
|
||||
return response.data
|
||||
},
|
||||
|
||||
// Получить свою статистику
|
||||
getMyStats: async (): Promise<UserStats> => {
|
||||
const response = await client.get<UserStats>('/users/me/stats')
|
||||
return response.data
|
||||
},
|
||||
|
||||
// Обновить никнейм
|
||||
updateNickname: async (data: UpdateNicknameData): Promise<User> => {
|
||||
const response = await client.patch<User>('/users/me', data)
|
||||
return response.data
|
||||
},
|
||||
|
||||
// Загрузить аватар
|
||||
uploadAvatar: async (file: File): Promise<User> => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const response = await client.post<User>('/users/me/avatar', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
return response.data
|
||||
},
|
||||
|
||||
// Сменить пароль
|
||||
changePassword: async (data: PasswordChangeData): Promise<{ message: string }> => {
|
||||
const response = await client.post<{ message: string }>('/users/me/password', data)
|
||||
return response.data
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user