Реальный контракт AURORA-1540/1751 не дал единой POST .../allocations: решение по строке разбито на PUT/DELETE .../vgo-assignments/rule (привязка/снятие правила) и PUT .../vgo-assignments/exclude (КФО), ответ — список VgoAssignmentOut, а не вся таблица. allocate() маршрутизирует по action и перечитывает таблицу сама — вызывающий код (CorrectionContent, CorrectionEditorModal) не менялся. Фейк контракта (CORRECTIONS_MOCK) убран — API уже есть. mockData/mockCalc остаются тестовыми фикстурами (R-27). Проверено на реальном стенде (Русский Бисквит — 2025 К1): загрузка таблицы, EXCLUDE/INCLUDE, ASSIGN, снятие правила, сохранение корректировки, экспорт — без ошибок в консоли.
53 lines
2.5 KiB
TypeScript
53 lines
2.5 KiB
TypeScript
import { api, apiFetchBlob } from '../../api/client';
|
||
import type {
|
||
AggregateKey,
|
||
AllocationIn,
|
||
CorrectionAggregateOut,
|
||
CorrectionIn,
|
||
CorrectionTableOut,
|
||
StatementType,
|
||
} from '../../types/corrections';
|
||
|
||
const STATEMENT_TYPE: StatementType = 'balance';
|
||
|
||
export function correctionsPath(versionId: string, key?: AggregateKey): string {
|
||
const base = `/consolidations/versions/${versionId}/corrections`;
|
||
if (!key) return base;
|
||
return `${base}/aggregates/${key.rule_id}/${key.company_1_id}/${key.company_2_id}`;
|
||
}
|
||
|
||
function vgoAssignmentPath(versionId: string, resource: 'rule' | 'exclude'): string {
|
||
return `/consolidations/versions/${versionId}/vgo-assignments/${resource}`;
|
||
}
|
||
|
||
export function getCorrectionTable(versionId: string): Promise<CorrectionTableOut> {
|
||
return api.get<CorrectionTableOut>(correctionsPath(versionId), { statement_type: STATEMENT_TYPE });
|
||
}
|
||
|
||
export function saveCorrection(versionId: string, key: AggregateKey, body: CorrectionIn): Promise<CorrectionAggregateOut> {
|
||
return api.put<CorrectionAggregateOut>(correctionsPath(versionId, key), body);
|
||
}
|
||
|
||
/**
|
||
* Решение по строке ОСВ: нет единой ручки — сервер (arm-core #208) разделил её на привязку/снятие правила и
|
||
* включение/исключение из КФО (`vgo-assignments/rule`, `vgo-assignments/exclude`), ответ — список решений по
|
||
* исходным строкам, а не таблица. Таблицу перечитываем сами, чтобы вызывающий код (CorrectionContent,
|
||
* CorrectionEditorModal) остался на прежнем контракте «действие -> актуальная таблица».
|
||
*/
|
||
export async function allocate(versionId: string, body: AllocationIn): Promise<CorrectionTableOut> {
|
||
const { statement_type, entry_ids, action } = body;
|
||
if (action === 'ASSIGN') {
|
||
if (!body.rule_id) throw new Error('ASSIGN без rule_id');
|
||
await api.put(vgoAssignmentPath(versionId, 'rule'), { entry_ids, rule_id: body.rule_id });
|
||
} else if (action === 'UNASSIGN' || action === 'RESET') {
|
||
await api.del(vgoAssignmentPath(versionId, 'rule'), { statement_type, entry_ids });
|
||
} else {
|
||
await api.put(vgoAssignmentPath(versionId, 'exclude'), { statement_type, entry_ids, is_exclude: action === 'EXCLUDE' });
|
||
}
|
||
return getCorrectionTable(versionId);
|
||
}
|
||
|
||
export function exportCorrectionTable(versionId: string): Promise<{ blob: Blob; filename: string | null }> {
|
||
return apiFetchBlob(`${correctionsPath(versionId)}/export?statement_type=${STATEMENT_TYPE}`);
|
||
}
|