Files
memegoat/frontend/src/services/user.service.ts
Mathis HERRIOT aa17c57e26 feat: add data export functionality to settings page and update admin reports table
- Introduced "Export Data" card in settings for exporting user data as a JSON file.
- Added `exportData` method to `UserService` for handling data export requests.
- Updated admin reports table with a new "Cible" column to display target information.
2026-01-29 13:57:07 +01:00

62 lines
1.4 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 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<any> {
const { data } = await api.get("/users/me/export");
return data;
},
};