fix(management): align user permissions with API

This commit is contained in:
yelan
2026-09-01 18:20:04 +08:00
parent dc86ee9149
commit fa42b89136
8 changed files with 226 additions and 34 deletions
+19 -3
View File
@@ -6,6 +6,7 @@ import type {
BackendCollection,
CreateRoleRequest,
RoleRecord,
RoleQuery,
RoleResponseDto,
UpdateRoleRequest,
} from './types'
@@ -21,18 +22,33 @@ function normalizeRole(dto: RoleResponseDto, index: number): RoleRecord {
name: dto.name,
description: dto.description ?? '—',
color: fallbackColors[index % fallbackColors.length],
userCount: dto.userCount ?? 0,
userCount: dto.userCount ?? undefined,
status: dto.status ?? 'ENABLED',
}
}
export function getRoles(): Promise<RoleRecord[]> {
function toBackendQuery(query: RoleQuery) {
const params: Record<string, string | number> = {
page: Math.max(query.page, 1),
size: Math.min(Math.max(query.pageSize, 1), 200),
}
if (query.keyword?.trim()) {
params.keyword = query.keyword.trim()
}
return params
}
export function getRoles(query: RoleQuery = { page: 1, pageSize: 200 }): Promise<RoleRecord[]> {
if (useMockData) {
return Promise.resolve([])
}
return request
.get<ApiResponse<BackendCollection<RoleResponseDto>>>('/v1/roles')
.get<ApiResponse<BackendCollection<RoleResponseDto>>>('/v1/roles', {
params: toBackendQuery(query),
})
.then(unwrapApiResponse)
.then((data) => {
const records = Array.isArray(data)