Introduce `avatarUrl` and `bio` fields in the user schema. Update repository, service, and controller to handle avatar uploads, processing, and bio updates. Add S3 integration for avatar storage and enhance user data handling for private and public profiles.
48 lines
1.1 KiB
TypeScript
48 lines
1.1 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 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;
|
|
},
|
|
};
|