admin_ruspet/src/api/departments.ts

47 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import apiClient from './client'
import type { Department, ApiResponse } from '@/types/api'
export interface DepartmentsListParams {
offset?: number
limit?: number
is_active?: boolean
name?: string
code?: string
}
export interface CreateDepartmentRequest {
name: string
code: string
description?: string
is_active?: boolean
}
export interface UpdateDepartmentRequest {
id: number
name?: string
code?: string
description?: string
is_active?: boolean
}
export const departmentsApi = {
// Получить список отделов с пагинацией и фильтрами
getList: (params: DepartmentsListParams = {}) =>
apiClient.get<ApiResponse<Department[]>>('/departments', { params }),
// Получить отдел по ID
getById: (id: number) =>
apiClient.get<Department>(`/departments/${id}`),
// Создать отдел
create: (data: CreateDepartmentRequest) =>
apiClient.post<Department>('/departments', data),
// Обновить отдел
update: (data: UpdateDepartmentRequest) =>
apiClient.put<Department>('/departments', data),
// Удалить отдел
delete: (id: number) =>
apiClient.delete<boolean>('/departments', { data: { id } }),
}