| | |
| | |
| | |
| |
|
| | import api from './api-wrapper.ts'; |
| | import type { |
| | UserRegisterRequest, |
| | UserRegisterResponse, |
| | UserUpdateNameRequest, |
| | UserUpdateNameResponse, |
| | User, |
| | } from '../types/user.types.ts'; |
| | import { API_ENDPOINTS } from '../constants/index.ts'; |
| | import { getUserId } from '../utils/index.ts'; |
| |
|
| | |
| | |
| | |
| | export async function registerUser( |
| | request: UserRegisterRequest |
| | ): Promise<UserRegisterResponse> { |
| | return api.post<UserRegisterResponse, UserRegisterRequest>( |
| | API_ENDPOINTS.USER_REGISTER, |
| | request |
| | ); |
| | } |
| |
|
| | |
| | |
| | |
| | export async function getCurrentUser(): Promise<User> { |
| | const userId = getUserId(); |
| | if (!userId) { |
| | throw new Error('User ID not found in localStorage'); |
| | } |
| |
|
| | return api.get<User>(API_ENDPOINTS.USER_ME, { |
| | headers: { |
| | 'X-User-ID': userId, |
| | }, |
| | }); |
| | } |
| |
|
| | |
| | |
| | |
| | export async function getUserByUniqueId( |
| | uniqueId: string |
| | ): Promise<User> { |
| | return api.get<User>( |
| | `${API_ENDPOINTS.USER_BY_UNIQUE_ID}?unique_id=${encodeURIComponent(uniqueId)}` |
| | ); |
| | } |
| |
|
| | |
| | |
| | |
| | export async function updateUserName( |
| | request: UserUpdateNameRequest |
| | ): Promise<UserUpdateNameResponse> { |
| | const userId = getUserId(); |
| | if (!userId) { |
| | throw new Error('User ID not found in localStorage'); |
| | } |
| |
|
| | return api.patch<UserUpdateNameResponse, UserUpdateNameRequest>( |
| | API_ENDPOINTS.USER_UPDATE_NAME, |
| | request, |
| | { |
| | headers: { |
| | 'X-User-ID': userId, |
| | }, |
| | } |
| | ); |
| | } |
| |
|
| |
|