Files
memegoat/frontend/src/services/user.service.ts
Mathis HERRIOT e2146f4502 feat: update exportData method with improved type annotations
- Refined `exportData` method to use `Record<string, unknown>` for more precise type safety.
2026-01-29 16:09:00 +01:00

69 lines
1.6 KiB
TypeScript

import api from "@/lib/api";
import type { User } from "@/types/user";
export const UserService = {
async getMe(): Promise<User> {
const { data } = await api.get<User>("/users/me");
return data;
},
async getProfile(username: string): Promise<User> {
const { data } = await api.get<User>(`/users/public/${username}`);
return data;
},
async search(query: string): Promise<User[]> {
const { data } = await api.get<User[]>("/users/search", {
params: { q: query },
});
return data;
},
async updateMe(update: Partial<User>): Promise<User> {
const { data } = await api.patch<User>("/users/me", update);
return data;
},
async removeMe(): Promise<void> {
await api.delete("/users/me");
},
async getUsersAdmin(
limit = 10,
offset = 0,
): Promise<{ data: User[]; totalCount: number }> {
const { data } = await api.get<{ data: User[]; totalCount: number }>(
"/users/admin",
{
params: { limit, offset },
},
);
return data;
},
async removeUserAdmin(uuid: string): Promise<void> {
await api.delete(`/users/${uuid}`);
},
async updateAdmin(uuid: string, update: Partial<User>): Promise<User> {
const { data } = await api.patch<User>(`/users/admin/${uuid}`, update);
return data;
},
async updateAvatar(file: File): Promise<User> {
const formData = new FormData();
formData.append("file", file);
const { data } = await api.post<User>("/users/me/avatar", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
return data;
},
async exportData(): Promise<Record<string, unknown>> {
const { data } = await api.get<Record<string, unknown>>("/users/me/export");
return data;
},
};