Files
ERP_Distribution/distribution_fe/lib/api/users.ts
T
Kalana B. Thilakarathna 0052725b88 feat: add user and role view sheets with detailed information display
- Created UserViewSheet component to display user details including username, full name, role, status, and timestamps.
- Created RoleViewSheet component to display role details including name, level, status, creation date, and associated permissions.
- Introduced permissions configuration in a new permissions.ts file, defining categories and permission codes for better management.
- Implemented middleware for authentication, ensuring access control for protected routes.
2026-10-18 23:11:01 +05:30

74 lines
2.4 KiB
TypeScript

import { api } from '@/lib/api'
import type { UserResponse, RoleResponse, PermissionResponse } from '@/types/api'
// ─── Users ────────────────────────────────────────────────────────────────────
export interface CreateUserBody {
username: string
password: string
fullName: string
roleId: string
reportsToUserId?: string | null
}
export interface UpdateUserBody {
fullName: string
}
export const users = {
list: () =>
api.get<UserResponse[]>('/users').then(r => r.data),
get: (id: string) =>
api.get<UserResponse>(`/users/${id}`).then(r => r.data),
create: (body: CreateUserBody) =>
api.post<UserResponse>('/users', body).then(r => r.data),
update: (id: string, body: UpdateUserBody) =>
api.put<UserResponse>(`/users/${id}`, body).then(r => r.data),
assignRole: (id: string, roleId: string) =>
api.put<UserResponse>(`/users/${id}/role`, { roleId }).then(r => r.data),
deactivate: (id: string) =>
api.delete(`/users/${id}`),
}
// ─── Roles ────────────────────────────────────────────────────────────────────
export interface RoleBody {
name: string
level: number
}
export const roles = {
list: () =>
api.get<RoleResponse[]>('/roles').then(r => r.data),
get: (id: string) =>
api.get<RoleResponse>(`/roles/${id}`).then(r => r.data),
getPermissions: (id: string) =>
api.get<PermissionResponse[]>(`/roles/${id}/permissions`).then(r => r.data),
create: (body: RoleBody) =>
api.post<RoleResponse>('/roles', body).then(r => r.data),
update: (id: string, body: 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),
deactivate: (id: string) =>
api.delete(`/roles/${id}`),
}
// ─── Permissions ──────────────────────────────────────────────────────────────
export const permissions = {
list: () =>
api.get<PermissionResponse[]>('/permissions').then(r => r.data),
}