feat: мультироль
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m6s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 26s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m6s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 26s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
This commit is contained in:
@@ -70,8 +70,8 @@ export const usersApi = {
|
||||
)
|
||||
return extractItems(payload)
|
||||
},
|
||||
setRole: (id: string | number, role: 'Student' | 'Teacher' | 'Admin') =>
|
||||
apiRequest<void>(`/users/${id}/role`, { method: 'PATCH', body: JSON.stringify(role) }),
|
||||
setRole: (id: string | number, roles: Array<'Student' | 'Teacher' | 'Admin'>) =>
|
||||
apiRequest<void>(`/users/${id}/role`, { method: 'PATCH', body: JSON.stringify(roles) }),
|
||||
setActive: (id: string | number, isActive: boolean) =>
|
||||
apiRequest<void>(`/users/${id}/active`, { method: 'PATCH', body: JSON.stringify(isActive) }),
|
||||
}
|
||||
|
||||
@@ -16,12 +16,26 @@ export function mapApiRole(role: string | undefined): UserRole {
|
||||
return 'student'
|
||||
}
|
||||
|
||||
function mapApiRoles(roles: string[] | undefined): UserRole[] {
|
||||
if (!roles?.length) return ['student']
|
||||
return Array.from(new Set(roles.map(mapApiRole)))
|
||||
}
|
||||
|
||||
function getDefaultActiveRole(roles: UserRole[]): UserRole {
|
||||
if (roles.includes('student')) return 'student'
|
||||
if (roles.includes('teacher')) return 'teacher'
|
||||
if (roles.includes('admin')) return 'admin'
|
||||
return 'student'
|
||||
}
|
||||
|
||||
export function mapApiUser(user: UserAuthDto | UserDto, stats?: UserStatsDto): User {
|
||||
const roles = mapApiRoles(user.roles)
|
||||
return {
|
||||
id: String(user.id),
|
||||
name: user.displayName || user.email || 'Пользователь UniVerse',
|
||||
email: user.email || '',
|
||||
role: mapApiRole(user.role),
|
||||
roles,
|
||||
activeRole: getDefaultActiveRole(roles),
|
||||
avatar: 'avatarUrl' in user ? user.avatarUrl ?? undefined : undefined,
|
||||
institute: 'ЮФУ',
|
||||
department: '',
|
||||
|
||||
@@ -32,7 +32,7 @@ export interface UserAuthDto {
|
||||
id: number
|
||||
email: string
|
||||
displayName?: string | null
|
||||
role: ApiUserRole
|
||||
roles: ApiUserRole[]
|
||||
}
|
||||
|
||||
export interface UserDto extends UserAuthDto {
|
||||
|
||||
Reference in New Issue
Block a user