Fix fow Top Protocol graph in Dashboard

This commit is contained in:
proitlab committed 2026-07-20 14:10:40 +07:00
1 parent bb1bb33cbd
commit 031d89101e
1 file changed
+7 -6
+7 -6
View File
@@ -1,6 +1,6 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const { AppStat, ProtocolStat, AppCategoryStat, LookupApp } = require('../../models/Schemas'); const { AppStat, ProtocolStat, AppCategoryStat, LookupApp, Flow } = require('../../models/Schemas');
const { getTimeFilter, getBaseFilter } = require('./helpers'); const { getTimeFilter, getBaseFilter } = require('./helpers');
// GET /api/dashboard/apps // GET /api/dashboard/apps
@@ -44,17 +44,18 @@ router.get('/protocols', async (req, res) => {
const base = getBaseFilter(req, timeFilter); const base = getBaseFilter(req, timeFilter);
const pipeline = [ const pipeline = [
{ $match: base }, { $match: { ...base, protocol: { $ne: null, $ne: '' } } },
{ $group: { { $group: {
_id: '$protocol_label', _id: '$protocol',
download: { $sum: '$download' }, download: { $sum: '$download' },
upload: { $sum: '$upload' }, upload: { $sum: '$upload' },
flows: { $sum: '$flows' }, flows: { $sum: 1 },
}}, }},
{ $sort: { download: -1 } } { $sort: { download: -1 } },
{ $limit: 20 }
]; ];
const result = await ProtocolStat.aggregate(pipeline); const result = await Flow.aggregate(pipeline);
const formatted = result.map(r => ({ const formatted = result.map(r => ({
protocol_label: r._id, protocol_label: r._id,
download: r.download || 0, download: r.download || 0,