frontend fully integreated with the backend
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { api } from '@/lib/api'
|
||||
import type {
|
||||
PaginatedResponse,
|
||||
UserResponse,
|
||||
RoleResponse,
|
||||
PermissionResponse,
|
||||
} from '@/types/api'
|
||||
|
||||
import type { PageParams } from './master'
|
||||
|
||||
// ─── Users ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface UserBody {
|
||||
username: string
|
||||
fullName: string
|
||||
roleId: string
|
||||
reportsToUserId?: string | null
|
||||
password?: string
|
||||
isActive?: boolean
|
||||
}
|
||||
|
||||
export interface UserListParams extends PageParams {
|
||||
roleId?: string
|
||||
search?: string
|
||||
}
|
||||
|
||||
export const users = {
|
||||
list: (params?: UserListParams) =>
|
||||
api.get<PaginatedResponse<UserResponse>>('/users', { params }).then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<UserResponse>(`/users/${id}`).then(r => r.data),
|
||||
|
||||
create: (body: UserBody) =>
|
||||
api.post<UserResponse>('/users', body).then(r => r.data),
|
||||
|
||||
update: (id: string, body: Partial<UserBody>) =>
|
||||
api.put<UserResponse>(`/users/${id}`, body).then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Roles ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface RoleBody {
|
||||
name: string
|
||||
level: number
|
||||
isActive?: boolean
|
||||
}
|
||||
|
||||
export interface RoleWithPermissions extends RoleResponse {
|
||||
permissions: PermissionResponse[]
|
||||
}
|
||||
|
||||
export const roles = {
|
||||
list: () =>
|
||||
api.get<RoleResponse[]>('/roles').then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<RoleWithPermissions>(`/roles/${id}`).then(r => r.data),
|
||||
|
||||
create: (body: RoleBody) =>
|
||||
api.post<RoleResponse>('/roles', body).then(r => r.data),
|
||||
|
||||
update: (id: string, body: Partial<RoleBody>) =>
|
||||
api.put<RoleResponse>(`/roles/${id}`, body).then(r => r.data),
|
||||
|
||||
assignPermissions: (id: string, permissionIds: string[]) =>
|
||||
api.put(`/roles/${id}/permissions`, { permissionIds }).then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Permissions ──────────────────────────────────────────────────────────────
|
||||
|
||||
export const permissions = {
|
||||
list: () =>
|
||||
api.get<PermissionResponse[]>('/permissions').then(r => r.data),
|
||||
}
|
||||
Reference in New Issue
Block a user