82 lines
3.2 KiB
TypeScript
82 lines
3.2 KiB
TypeScript
import { httpClient } from '../../../core/infrastructure/httpClient';
|
||
import type { User, UserPresence } from '../../../core/domain/types';
|
||
|
||
export class UserApi {
|
||
static async searchUsers(query: string) {
|
||
// Конечная точка в новом бэкенде: GET /api/profiles/search?q=...
|
||
return httpClient.request<UserPresence[]>(`/profiles/search?q=${encodeURIComponent(query)}`);
|
||
}
|
||
|
||
static async getUser(id: string) {
|
||
// Основной путь по ТЗ: GET /api/users/{id}; старый профильный путь оставлен на бэкенде.
|
||
return httpClient.request<User>(`/users/${id}`);
|
||
}
|
||
|
||
static async updateProfile(data: {
|
||
displayName?: string;
|
||
bio?: string;
|
||
birthday?: string | null;
|
||
statusText?: string | null;
|
||
statusEmoji?: string | null;
|
||
statusExpiresAt?: string | null;
|
||
}) {
|
||
// Основной путь по ТЗ: PATCH /api/user/profile
|
||
const payload = {
|
||
...data,
|
||
about: data.bio // Дублируем для совместимости
|
||
};
|
||
return httpClient.request<User>('/user/profile', {
|
||
method: 'PATCH',
|
||
body: JSON.stringify(payload),
|
||
});
|
||
}
|
||
|
||
static async updateSettings(settings: any) {
|
||
// Конечная точка в новом бэкенде: PUT /api/profiles/settings
|
||
return httpClient.request('/profiles/settings', {
|
||
method: 'PUT',
|
||
body: JSON.stringify(settings),
|
||
});
|
||
}
|
||
|
||
static async uploadAvatar(file: File) {
|
||
// Конечная точка в новом бэкенде: POST /api/profiles/avatar
|
||
const formData = new FormData();
|
||
formData.append('avatar', file);
|
||
return httpClient.request<User>('/profiles/avatar', {
|
||
method: 'POST',
|
||
body: formData,
|
||
timeout: 120_000, // Аватар может быть большим, даем время на обработку
|
||
});
|
||
}
|
||
|
||
static async cropAvatar(file: File, cropData: { x: number; y: number; width: number; height: number; sw: number; sh: number }) {
|
||
// Конечная точка в новом бэкенде: POST /api/profiles/avatar/crop
|
||
const formData = new FormData();
|
||
formData.append('avatar', file);
|
||
formData.append('x', cropData.x.toString());
|
||
formData.append('y', cropData.y.toString());
|
||
formData.append('width', cropData.width.toString());
|
||
formData.append('height', cropData.height.toString());
|
||
formData.append('sw', cropData.sw.toString());
|
||
formData.append('sh', cropData.sh.toString());
|
||
|
||
return httpClient.request<User>('/profiles/avatar/crop', {
|
||
method: 'POST',
|
||
body: formData,
|
||
timeout: 120_000,
|
||
});
|
||
}
|
||
|
||
static async removeAvatar() {
|
||
// Конечная точка в новом бэкенде: DELETE /api/profiles/avatar
|
||
return httpClient.request<User>('/profiles/avatar', { method: 'DELETE' });
|
||
}
|
||
|
||
static async getIceServers() {
|
||
// Конфигурация WebRTC теперь возвращается через эндпоинт админки или настроек,
|
||
// но если бэк не меняли в этой части, оставляем старый путь.
|
||
return httpClient.request<{ iceServers: RTCIceServer[] }>('/webrtc/ice-servers');
|
||
}
|
||
}
|