Enhanced the group management system by introducing dynamic group capabilities, allowing for the exclusion of elements from dynamic groups. Updated the Group and GroupItem models to support a new GroupMode, enabling the distinction between static and dynamic groups. Implemented API endpoints for excluding elements and updated related services to handle group composition based on the selected mode. Improved the frontend to accommodate these changes, including new API functions and UI components for managing exclusions and group modes, thereby enhancing the overall user experience in group management.
103 lines
3.2 KiB
TypeScript
103 lines
3.2 KiB
TypeScript
import { apiRequest } from '@/shared/api/client'
|
|
import type {
|
|
CreatedIdResponse,
|
|
GroupCandidateDto,
|
|
GroupDto,
|
|
GroupElementKind,
|
|
GroupFilter,
|
|
GroupMode,
|
|
GroupSuggestionDto,
|
|
GroupSummaryDto,
|
|
} from '@/shared/api/types'
|
|
|
|
export function listGroups() {
|
|
return apiRequest<GroupSummaryDto[]>('/admin/groups')
|
|
}
|
|
|
|
export function getGroup(id: string) {
|
|
return apiRequest<GroupDto>(`/admin/groups/${id}`)
|
|
}
|
|
|
|
export function createGroup(body: { name: string; description?: string }) {
|
|
return apiRequest<CreatedIdResponse>('/admin/groups', { method: 'POST', body })
|
|
}
|
|
|
|
export function updateGroup(
|
|
id: string,
|
|
body: {
|
|
name: string
|
|
description: string | null
|
|
filter: GroupFilter | null
|
|
/** Не передан — режим остаётся прежним. */
|
|
mode?: GroupMode
|
|
},
|
|
) {
|
|
return apiRequest<void>(`/admin/groups/${id}`, { method: 'PUT', body })
|
|
}
|
|
|
|
export function deleteGroup(id: string) {
|
|
return apiRequest<void>(`/admin/groups/${id}`, { method: 'DELETE' })
|
|
}
|
|
|
|
/** Подбор по правилу набора. Фильтр передаётся явно — редактор крутит его до сохранения. */
|
|
export function findGroupCandidates(id: string, filter: GroupFilter | null) {
|
|
return apiRequest<GroupCandidateDto[]>(`/admin/groups/${id}/candidates`, {
|
|
method: 'POST',
|
|
body: { filter },
|
|
})
|
|
}
|
|
|
|
/** Что имеет смысл завести группой при нынешней библиотеке. */
|
|
export function suggestGroups() {
|
|
return apiRequest<GroupSuggestionDto[]>('/admin/groups/suggestions')
|
|
}
|
|
|
|
/** Создаёт группу по предложению: имя, правило и состав сервер берёт по ключу сам. */
|
|
export function createGroupFromSuggestion(key: string) {
|
|
return apiRequest<CreatedIdResponse>('/admin/groups/suggestions', {
|
|
method: 'POST',
|
|
body: { key },
|
|
})
|
|
}
|
|
|
|
export function addGroupElements(
|
|
id: string,
|
|
elements: { elementKind: GroupElementKind; elementId: string }[],
|
|
) {
|
|
return apiRequest<{ added: number }>(`/admin/groups/${id}/items`, {
|
|
method: 'POST',
|
|
body: { elements },
|
|
})
|
|
}
|
|
|
|
/** Исключить элемент из вычисленного состава динамической группы либо вернуть его правилу. */
|
|
export function excludeGroupElement(
|
|
id: string,
|
|
element: { elementKind: GroupElementKind; elementId: string },
|
|
excluded: boolean,
|
|
) {
|
|
return apiRequest<void>(`/admin/groups/${id}/exclusions`, {
|
|
method: 'POST',
|
|
body: { ...element, excluded },
|
|
})
|
|
}
|
|
|
|
export function removeGroupItem(id: string, itemId: string) {
|
|
return apiRequest<void>(`/admin/groups/${id}/items/${itemId}`, { method: 'DELETE' })
|
|
}
|
|
|
|
export function setGroupItemWeight(id: string, itemId: string, weight: number) {
|
|
return apiRequest<void>(`/admin/groups/${id}/items/${itemId}/weight`, {
|
|
method: 'PUT',
|
|
body: { weight },
|
|
})
|
|
}
|
|
|
|
/** Порядок позиций: не упомянутые остаются после перечисленных. */
|
|
export function reorderGroup(id: string, itemIdsInOrder: string[]) {
|
|
return apiRequest<void>(`/admin/groups/${id}/order`, {
|
|
method: 'PUT',
|
|
body: { itemIdsInOrder },
|
|
})
|
|
}
|