99 lines
2.5 KiB
TypeScript
99 lines
2.5 KiB
TypeScript
import api from './api'
|
|
import type { ListUserResponse, ListRoleResponse } from '~/types/setting'
|
|
|
|
interface SyncRolePayload {
|
|
client_role: string[]
|
|
email: string
|
|
keycloak_id: string
|
|
name: string
|
|
}
|
|
|
|
interface MenuItem {
|
|
title?: string
|
|
icon?: string
|
|
to?: string
|
|
children?: MenuItem[] | null
|
|
}
|
|
|
|
interface MenuGroup {
|
|
id: string
|
|
header: string
|
|
children: MenuItem[]
|
|
}
|
|
|
|
interface MenuResponse {
|
|
success: boolean
|
|
code: number
|
|
message: string
|
|
data: MenuGroup[]
|
|
}
|
|
|
|
export const syncRole = async (payload: SyncRolePayload, customToken: string): Promise<any> => {
|
|
try {
|
|
const response = await api.post('/access/sync-keycloak-role', payload, {
|
|
headers: {
|
|
'Authorization': `Bearer ${customToken}`
|
|
}
|
|
})
|
|
return response.data
|
|
} catch (error) {
|
|
console.error('Error syncing role:', error)
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const getUserAccess = async (userId: string, customToken: string): Promise<MenuResponse | null> => {
|
|
try {
|
|
const response = await api.get(`/access/eligible-menu?keycloak_id=${userId}`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${customToken}`
|
|
}
|
|
})
|
|
return response.data
|
|
} catch (error: any) {
|
|
console.error('❌ Error getting user access:', {
|
|
message: error?.message,
|
|
response: error?.response?.data,
|
|
status: error?.response?.status
|
|
})
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const getListUser = async (params: {
|
|
limit?: number;
|
|
offset?: number;
|
|
search?: string;
|
|
} = {}): Promise<ListUserResponse | null> => {
|
|
try {
|
|
const response = await api.get('/access/list-user', { params })
|
|
return response.data
|
|
} catch (error) {
|
|
console.error('Error getting list user:', error)
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const getListRole = async (params: {
|
|
limit?: number;
|
|
offset?: number;
|
|
search?: string;
|
|
} = {}): Promise<ListRoleResponse | null> => {
|
|
try {
|
|
const response = await api.get('/access/role-permission', { params })
|
|
return response.data
|
|
} catch (error) {
|
|
console.error('Error getting list role:', error)
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const getListRoleById = async (id: string ) => {
|
|
const response = await api.get(`/access/role-permission/${id}`)
|
|
return response.data
|
|
}
|
|
|
|
export const updateRolePage = async (id: string, data: any) => {
|
|
const response = await api.put(`/access/role-permission/${id}`, data)
|
|
return response.data
|
|
} |