mirror of
https://github.com/Foltik/Shimapan
synced 2025-01-06 00:08:25 -05:00
Finish stats tests and fix all time calculation
This commit is contained in:
parent
6820a4d2c6
commit
137b47cf0b
@ -72,7 +72,6 @@ router.get('/week', requireAuth('stats.get'), wrap(async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]).toArray());
|
]).toArray());
|
||||||
|
|
||||||
const viewStats = await (View.collection.aggregate([
|
const viewStats = await (View.collection.aggregate([
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
@ -105,7 +104,7 @@ router.get('/week', requireAuth('stats.get'), wrap(async (req, res) => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
router.get('/all', requireAuth('stats.get'), wrap(async (req, res) => {
|
router.get('/all', requireAuth('stats.get'), wrap(async (req, res) => {
|
||||||
const stats = await (Upload.collection.aggregate([
|
const uploadStats = await (Upload.collection.aggregate([
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
'uploader': req.username
|
'uploader': req.username
|
||||||
@ -113,7 +112,6 @@ router.get('/all', requireAuth('stats.get'), wrap(async (req, res) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
'views': '$views',
|
|
||||||
'size': '$file.size'
|
'size': '$file.size'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -121,11 +119,25 @@ router.get('/all', requireAuth('stats.get'), wrap(async (req, res) => {
|
|||||||
$group: {
|
$group: {
|
||||||
'_id': 'total',
|
'_id': 'total',
|
||||||
'count': {$sum: 1},
|
'count': {$sum: 1},
|
||||||
'views': {$sum: '$views'},
|
|
||||||
'size': {$sum: '$size'}
|
'size': {$sum: '$size'}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]).toArray());
|
]).toArray());
|
||||||
|
const viewStats = await (View.collection.aggregate([
|
||||||
|
{
|
||||||
|
$match: {
|
||||||
|
'uploader': req.username
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
'_id': 'total',
|
||||||
|
'views': {$sum: 1},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).toArray());
|
||||||
|
|
||||||
|
const stats = mergeAggregations(uploadStats, viewStats);
|
||||||
|
|
||||||
res.status(200).json(stats);
|
res.status(200).json(stats);
|
||||||
}));
|
}));
|
||||||
|
@ -1021,8 +1021,13 @@ describe('Stats', () => {
|
|||||||
await setupUploadsAndViews();
|
await setupUploadsAndViews();
|
||||||
|
|
||||||
await util.createSession(agent, ['stats.get'], 'user');
|
await util.createSession(agent, ['stats.get'], 'user');
|
||||||
const stats = await util.getStatsAll(agent);
|
const stats = (await util.getStatsAll(agent)).body;
|
||||||
console.log(stats.body);
|
|
||||||
|
stats.should.have.property('total');
|
||||||
|
stats.total.should.have.property('count').equal(8);
|
||||||
|
stats.total.should.have.property('size').equal(8);
|
||||||
|
stats.total.should.have.property('views').equal(8);
|
||||||
|
|
||||||
await util.logout(agent);
|
await util.logout(agent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user