arm-core/web/src/services/api/documents.ts

24 lines
1.2 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 { api } from '../../api/client';
import type { DocumentOut, EntryOut, Page, StatementOut, StatementPatch } from '../../types/api';
const ENTRIES_PAGE = 2000;
export const getDocument = (id: string) => api.get<DocumentOut>(`/documents/${id}`);
export const confirmDocument = (id: string) => api.post<DocumentOut>(`/documents/${id}/confirm`);
export const getStatement = (id: string) => api.get<StatementOut>(`/documents/${id}/statement`);
export const patchStatement = (id: string, body: StatementPatch) => api.patch<StatementOut>(`/documents/${id}/statement`, body);
export const acceptChecks = (id: string, comment: string) =>
api.post<StatementOut>(`/documents/${id}/statement/checks/accept`, { comment });
/** Все строки ОСВ-документа (страницами по 2000). */
export async function getAllEntries(id: string): Promise<EntryOut[]> {
const all: EntryOut[] = [];
for (let offset = 0; ; offset += ENTRIES_PAGE) {
const page = await api.get<Page<EntryOut>>(`/documents/${id}/entries?limit=${ENTRIES_PAGE}&offset=${offset}`);
all.push(...page.items);
if (all.length >= page.total || page.items.length === 0) {
return all;
}
}
}