Paginate Olist monitor history
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m17s

This commit is contained in:
Cauê Faleiros
2026-08-13 13:44:59 -03:00
parent bee9e6dc2e
commit 5fbdd354c7
6 changed files with 134 additions and 45 deletions

View File

@@ -218,9 +218,13 @@ const refreshYieldRecommendations = async (client) => {
`);
};
const listProductionOrderImportData = async () => {
const [runs, recommendations, supplierRecommendations] = await Promise.all([
pool.query(`SELECT id, filename, status, total_rows, imported_count, updated_count, skipped_count, failed_count, error_message, started_at, completed_at FROM production_order_import_runs ORDER BY started_at DESC LIMIT 10;`),
const listProductionOrderImportData = async ({ runsPage = 1, runsPageSize = 5 } = {}) => {
const normalizedRunsPageSize = Math.max(1, Math.min(Number(runsPageSize) || 5, 20));
const normalizedRunsPage = Math.max(1, Number(runsPage) || 1);
const runsOffset = (normalizedRunsPage - 1) * normalizedRunsPageSize;
const [runs, runsCount, recommendations, supplierRecommendations] = await Promise.all([
pool.query(`SELECT id, filename, status, total_rows, imported_count, updated_count, skipped_count, failed_count, error_message, started_at, completed_at FROM production_order_import_runs ORDER BY started_at DESC LIMIT $1 OFFSET $2;`, [normalizedRunsPageSize, runsOffset]),
pool.query('SELECT COUNT(*)::int AS count FROM production_order_import_runs;'),
pool.query(`SELECT family_key, sample_count, yield_sample_count, roll_sample_count, avg_yield_pieces_per_kg, avg_kg_per_roll, recommended_units_per_roll, last_completed_date, updated_at FROM production_yield_recommendations ORDER BY family_key;`),
pool.query(`SELECT family_key, supplier, sample_count, yield_sample_count, roll_sample_count, avg_yield_pieces_per_kg, avg_kg_per_roll, recommended_units_per_roll, last_completed_date, updated_at FROM production_yield_supplier_recommendations ORDER BY family_key, supplier;`)
]);
@@ -231,6 +235,9 @@ const listProductionOrderImportData = async () => {
failed: row.failed_count, errorMessage: row.error_message || '', startedAt: row.started_at,
completedAt: row.completed_at
})),
runsTotal: Number(runsCount.rows[0]?.count || 0),
runsPage: normalizedRunsPage,
runsPageSize: normalizedRunsPageSize,
recommendations: recommendations.rows.map(row => ({
familyKey: row.family_key, sampleCount: Number(row.sample_count), yieldSampleCount: Number(row.yield_sample_count),
rollSampleCount: Number(row.roll_sample_count), avgYieldPiecesPerKg: row.avg_yield_pieces_per_kg === null ? null : Number(row.avg_yield_pieces_per_kg),