251210:1709 Frontend: reeactor organization and run build
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
admin
2025-12-10 17:09:11 +07:00
parent aa96cd90e3
commit c8a0f281ef
140 changed files with 3780 additions and 1473 deletions

View File

@@ -1,14 +1,32 @@
import apiClient from "@/lib/api/client";
import { CreateUserDto, UpdateUserDto, SearchUserDto, User } from "@/types/user";
const transformUser = (user: any): User => {
return {
...user,
userId: user.user_id,
roles: user.assignments?.map((a: any) => a.role) || [],
};
};
export const userService = {
getAll: async (params?: SearchUserDto) => {
const response = await apiClient.get<any>("/users", { params });
// Unwrap NestJS TransformInterceptor response
if (response.data?.data) {
return response.data.data as User[];
// Handle both paginated and non-paginated responses
let rawData = response.data?.data || response.data;
// If paginated (has .data property which is array)
if (rawData && Array.isArray(rawData.data)) {
rawData = rawData.data;
}
return response.data as User[];
// If still not array (e.g. error or empty), default to []
if (!Array.isArray(rawData)) {
return [];
}
return rawData.map(transformUser);
},
getRoles: async () => {
@@ -21,17 +39,17 @@ export const userService = {
getById: async (id: number) => {
const response = await apiClient.get<User>(`/users/${id}`);
return response.data;
return transformUser(response.data);
},
create: async (data: CreateUserDto) => {
const response = await apiClient.post<User>("/users", data);
return response.data;
return transformUser(response.data);
},
update: async (id: number, data: UpdateUserDto) => {
const response = await apiClient.put<User>(`/users/${id}`, data);
return response.data;
return transformUser(response.data);
},
delete: async (id: number) => {