mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 00:08:18 +00:00
fix(reports): stop the 'first N rows' option failing on large exports
The export path used one number for two different things: the format's hard row cap, and the caller's explicit 'give me the first N rows'. Because resolveExportCap() returned min(requested, formatCap) and runAll() then threw when the result reached it, picking 'Records: First 100' in the export dialog 400'd on any report with more than 100 rows — the user asked to be truncated and got an error instead. Splits them: formatRowCap() is the hard, non-caller-controllable ceiling that still throws when exceeded (a silently short file hides missing rows), while resolveRowLimit() is the deliberate truncation and is honoured by slicing. Verified against a 223-row dataset: limit=5 now returns 5 rows, and no limit returns all 223.
This commit is contained in:
@@ -12,9 +12,10 @@ import { FREIGHT_PERMS, reportPermissionKey } from '../../seed/freight-permissio
|
||||
import { UserTradeAccessService } from '../user-trade-access/user-trade-access.service';
|
||||
import {
|
||||
EXPORT_MIME,
|
||||
formatRowCap,
|
||||
pickByKey,
|
||||
resolveExportCap,
|
||||
resolveExportFormat,
|
||||
resolveRowLimit,
|
||||
} from '../exports/export-request.util';
|
||||
import { TabularExportService } from '../exports/tabular-export.service';
|
||||
import { RawReportQuery, ReportRunnerService } from './report-runner.service';
|
||||
@@ -101,10 +102,12 @@ export class ReportsController {
|
||||
const def = this.resolve(key, user);
|
||||
const directions = await this.userTradeAccessService.resolveAllowedDirections(user);
|
||||
const format = resolveExportFormat(query.format);
|
||||
const cap = resolveExportCap(format, query.limit);
|
||||
const exportColumns = pickByKey(def.columns, query.fields);
|
||||
|
||||
const { items, kpis } = await this.runner.runAll(def, query, directions, cap);
|
||||
const { items, kpis } = await this.runner.runAll(def, query, directions, {
|
||||
cap: formatRowCap(format),
|
||||
limit: resolveRowLimit(format, query.limit),
|
||||
});
|
||||
const doc = {
|
||||
title: def.title,
|
||||
description: def.description,
|
||||
|
||||
Reference in New Issue
Block a user