From a06d5ffaed7e7847b5bd893846d9792119911f13 Mon Sep 17 00:00:00 2001 From: diced Date: Mon, 6 Sep 2021 15:22:36 -0700 Subject: [PATCH] fix(api): sort images count and types count --- src/pages/api/stats.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/api/stats.ts b/src/pages/api/stats.ts index cc073a0..8089ae8 100644 --- a/src/pages/api/stats.ts +++ b/src/pages/api/stats.ts @@ -43,21 +43,19 @@ async function handler(req: NextApiReq, res: NextApiRes) { by: ['mimetype'], _count: { mimetype: true - } + }, }); const types_count = []; - for (let i = 0, L = typesCount.length; i !== L; ++i) { - types_count.push({ mimetype: typesCount[i].mimetype, count: typesCount[i]._count.mimetype }); - } + for (let i = 0, L = typesCount.length; i !== L; ++i) types_count.push({ mimetype: typesCount[i].mimetype, count: typesCount[i]._count.mimetype }); return res.json({ size: bytesToRead(size), size_num: size, count, - count_by_user, + count_by_user: count_by_user.sort((a,b) => b.count-a.count), count_users, views_count: (viewsCount[0]?._sum?.views ?? 0), - types_count + types_count: types_count.sort((a,b) => b.count-a.count) }); }