Files
memegoat/frontend/src/services/user.service.ts
Mathis HERRIOT 764c4c07c8 feat(users, contents): extend admin update functionality and role management
- Added `moderator` role to `User` type for improved role assignment flexibility.
- Introduced `updateAdmin` method in user and content services to handle partial admin-specific updates.
- Enhanced `Content` type with `categoryId` and `iconUrl` to support richer categorization.
2026-01-21 13:22:07 +01:00

53 lines
1.3 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 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;
},
};