238 lines
7.2 KiB
TypeScript
238 lines
7.2 KiB
TypeScript
import { api } from './api'
|
|
import type {
|
|
LoginResponse,
|
|
Project,
|
|
ProjectMember,
|
|
MemberRole,
|
|
UserListItem,
|
|
MenuItem,
|
|
Role,
|
|
SaveRoleRequest,
|
|
MasterDataItem,
|
|
SaveMasterDataRequest,
|
|
PagedResult,
|
|
UserRoleDetail,
|
|
User,
|
|
ActionLog,
|
|
LoginLog,
|
|
ActionLogFilters,
|
|
LoginLogFilters,
|
|
} from '../types'
|
|
|
|
export async function login(username: string, password: string): Promise<LoginResponse> {
|
|
const { data } = await api.post<LoginResponse>('/api/auth/login', { username, password })
|
|
return data
|
|
}
|
|
|
|
export async function getMenu(): Promise<MenuItem[]> {
|
|
const { data } = await api.get<MenuItem[]>('/api/settings/permission/menu')
|
|
return data
|
|
}
|
|
|
|
export async function getRoles(page = 1, pageSize = 20): Promise<PagedResult<Role>> {
|
|
const { data } = await api.get<PagedResult<Role>>('/api/settings/permission', { params: { page, pageSize } })
|
|
return data
|
|
}
|
|
|
|
export async function getRole(id: string): Promise<Role> {
|
|
const { data } = await api.get<Role>(`/api/settings/permission/${id}`)
|
|
return data
|
|
}
|
|
|
|
export async function createRole(payload: SaveRoleRequest): Promise<Role> {
|
|
const { data } = await api.post<Role>('/api/settings/permission', payload)
|
|
return data
|
|
}
|
|
|
|
export async function updateRole(id: string, payload: SaveRoleRequest): Promise<Role> {
|
|
const { data } = await api.put<Role>(`/api/settings/permission/${id}`, payload)
|
|
return data
|
|
}
|
|
|
|
export async function deleteRole(id: string): Promise<void> {
|
|
await api.delete(`/api/settings/permission/${id}`)
|
|
}
|
|
|
|
export async function getMasterDataList(params: {
|
|
group?: string
|
|
q?: string
|
|
isActive?: boolean
|
|
page?: number
|
|
pageSize?: number
|
|
} = {}): Promise<PagedResult<MasterDataItem>> {
|
|
const { data } = await api.get<PagedResult<MasterDataItem>>('/api/masterdata', { params })
|
|
return data
|
|
}
|
|
|
|
export async function getMasterDataByGroup(group: string): Promise<MasterDataItem[]> {
|
|
const { data } = await api.get<MasterDataItem[]>(`/api/masterdata/groups/${group}`)
|
|
return data
|
|
}
|
|
|
|
export async function getMasterDataOptions(group: string): Promise<{ label: string; value: string }[]> {
|
|
const items = await getMasterDataByGroup(group)
|
|
return items.map((i) => ({ label: i.label, value: i.value }))
|
|
}
|
|
|
|
export async function createMasterData(payload: SaveMasterDataRequest): Promise<MasterDataItem> {
|
|
const { data } = await api.post<MasterDataItem>('/api/masterdata', payload)
|
|
return data
|
|
}
|
|
|
|
export async function updateMasterData(id: string, payload: SaveMasterDataRequest): Promise<MasterDataItem> {
|
|
const { data } = await api.put<MasterDataItem>(`/api/masterdata/${id}`, payload)
|
|
return data
|
|
}
|
|
|
|
export async function deleteMasterData(id: string): Promise<void> {
|
|
await api.delete(`/api/masterdata/${id}`)
|
|
}
|
|
|
|
export async function getProjects(params: {
|
|
q?: string
|
|
status?: string
|
|
createdBy?: string
|
|
updatedBy?: string
|
|
page?: number
|
|
pageSize?: number
|
|
} = {}): Promise<PagedResult<Project>> {
|
|
const { data } = await api.get<PagedResult<Project>>('/api/projects', { params })
|
|
return data
|
|
}
|
|
|
|
export async function searchProjects(q: string): Promise<Project[]> {
|
|
const { data } = await api.get<Project[]>('/api/projects/search', { params: { q } })
|
|
return data
|
|
}
|
|
|
|
export async function getProject(id: string): Promise<Project> {
|
|
const { data } = await api.get<Project>(`/api/projects/${id}`)
|
|
return data
|
|
}
|
|
|
|
export async function createProject(name: string, description?: string): Promise<Project> {
|
|
const { data } = await api.post<Project>('/api/projects', { name, description })
|
|
return data
|
|
}
|
|
|
|
export async function updateProject(
|
|
id: string,
|
|
payload: { name: string; description: string | null; status: string },
|
|
): Promise<Project> {
|
|
const { data } = await api.put<Project>(`/api/projects/${id}`, payload)
|
|
return data
|
|
}
|
|
|
|
export async function deleteProject(id: string): Promise<void> {
|
|
await api.delete(`/api/projects/${id}`)
|
|
}
|
|
|
|
export async function getMembers(
|
|
projectId: string,
|
|
params: { q?: string; role?: string; page?: number; pageSize?: number } = {},
|
|
): Promise<PagedResult<ProjectMember>> {
|
|
const { data } = await api.get<PagedResult<ProjectMember>>(`/api/projects/${projectId}/members`, { params })
|
|
return data
|
|
}
|
|
|
|
export async function addMember(
|
|
projectId: string,
|
|
userId: string,
|
|
role: MemberRole,
|
|
): Promise<ProjectMember> {
|
|
const { data } = await api.post<ProjectMember>(`/api/projects/${projectId}/members`, { userId, role })
|
|
return data
|
|
}
|
|
|
|
export async function removeMember(projectId: string, userId: string): Promise<void> {
|
|
await api.delete(`/api/projects/${projectId}/members/${userId}`)
|
|
}
|
|
|
|
export async function updateMemberDocumentPermissions(
|
|
projectId: string,
|
|
userId: string,
|
|
payload: {
|
|
canViewDocuments: boolean
|
|
canCreateDocuments: boolean
|
|
canEditDocuments: boolean
|
|
canDeleteDocuments: boolean
|
|
},
|
|
): Promise<ProjectMember> {
|
|
const { data } = await api.put<ProjectMember>(`/api/projects/${projectId}/members/${userId}/document-permissions`, payload)
|
|
return data
|
|
}
|
|
|
|
export async function getProfile(): Promise<User> {
|
|
const { data } = await api.get<User>('/api/auth/me')
|
|
return data
|
|
}
|
|
|
|
export async function getUsers(q?: string): Promise<User[]> {
|
|
const { data } = await api.get<User[]>('/api/users/list', { params: { q } })
|
|
return data
|
|
}
|
|
|
|
export async function getUsersPaged(params: {
|
|
q?: string
|
|
isActive?: boolean
|
|
page?: number
|
|
pageSize?: number
|
|
} = {}): Promise<PagedResult<UserListItem>> {
|
|
const { data } = await api.get<PagedResult<UserListItem>>('/api/users', { params })
|
|
return data
|
|
}
|
|
|
|
export async function createUser(payload: {
|
|
username: string
|
|
displayName: string
|
|
password: string
|
|
roleId?: string
|
|
}): Promise<UserListItem> {
|
|
const { data } = await api.post<UserListItem>('/api/users', payload)
|
|
return data
|
|
}
|
|
|
|
export async function updateUser(
|
|
id: string,
|
|
payload: { displayName: string; roleId?: string; isActive: boolean },
|
|
): Promise<UserListItem> {
|
|
const { data } = await api.put<UserListItem>(`/api/users/${id}`, payload)
|
|
return data
|
|
}
|
|
|
|
export async function deleteUser(id: string): Promise<void> {
|
|
await api.delete(`/api/users/${id}`)
|
|
}
|
|
|
|
export async function resetUserPassword(id: string, newPassword: string): Promise<void> {
|
|
await api.post(`/api/users/${id}/reset-password`, { newPassword })
|
|
}
|
|
|
|
export async function getUserRoles(userId: string): Promise<UserRoleDetail> {
|
|
const { data } = await api.get<UserRoleDetail>(`/api/users/${userId}/roles`)
|
|
return data
|
|
}
|
|
|
|
export async function assignUserRole(userId: string, roleId: string): Promise<void> {
|
|
await api.post(`/api/users/${userId}/roles`, { roleId })
|
|
}
|
|
|
|
export async function unassignUserRole(userId: string, roleId: string): Promise<void> {
|
|
await api.delete(`/api/users/${userId}/roles/${roleId}`)
|
|
}
|
|
|
|
export async function getUserPermissions(userId: string): Promise<MenuItem[]> {
|
|
const { data } = await api.get<MenuItem[]>(`/api/users/${userId}/permissions`)
|
|
return data
|
|
}
|
|
|
|
export async function getActionLogs(params: ActionLogFilters = {}): Promise<PagedResult<ActionLog>> {
|
|
const { data } = await api.get<PagedResult<ActionLog>>('/api/audit/actions', { params })
|
|
return data
|
|
}
|
|
|
|
export async function getLoginLogs(params: LoginLogFilters = {}): Promise<PagedResult<LoginLog>> {
|
|
const { data } = await api.get<PagedResult<LoginLog>>('/api/audit/logins', { params })
|
|
return data
|
|
}
|